R-Type 0.1
Loading...
Searching...
No Matches
HandshakeHeader.hpp
1#pragma once
2
8#include "PacketReader.hpp"
9#include "PacketWriter.hpp"
10#include <cstddef>
11#include <cstdint>
12
14constexpr std::uint32_t MAGIC = 0x52545950;
16constexpr std::uint8_t VERSION = 1;
17
21enum class HandshakeType : std::uint8_t {
22 Hello = 1,
23 Welcome = 2,
24 Rejected = 3,
25};
26
39 std::uint32_t magic = MAGIC;
40 std::uint8_t version = VERSION;
42
44 static constexpr std::size_t HEADER_SIZE = 6;
45
51 bool serialize(PacketWriter &writer) const;
52
58 bool deserialize(PacketReader &reader);
59};
60
Bounds checked reader of big-endian values over a byte buffer.
Definition PacketReader.hpp:15
Growable buffer of big-endian values, capped at MAX_PAYLOAD_SIZE.
Definition PacketWriter.hpp:16
HandshakeType
Kind of handshake datagram.
Definition HandshakeHeader.hpp:21
constexpr std::uint8_t VERSION
Protocol version announced and expected during the handshake.
Definition HandshakeHeader.hpp:16
constexpr std::uint32_t MAGIC
Magic number that starts every handshake datagram, "RTYP" in ASCII.
Definition HandshakeHeader.hpp:14
@ Welcome
Server accepts the client and gives its connection id.
@ Hello
Client asks the server to open a connection.
@ Rejected
Server refuses the connection.
Header of the datagrams exchanged before a connection exists.
Definition HandshakeHeader.hpp:38
static constexpr std::size_t HEADER_SIZE
Encoded size of the header, in bytes.
Definition HandshakeHeader.hpp:44
HandshakeType type
Handshake step.
Definition HandshakeHeader.hpp:41
bool deserialize(PacketReader &reader)
Reads and validates the magic number and handshake type.
Definition HandshakeHeader.cpp:9
std::uint8_t version
Protocol version.
Definition HandshakeHeader.hpp:40
bool serialize(PacketWriter &writer) const
Writes the header in network byte order.
Definition HandshakeHeader.cpp:4
std::uint32_t magic
Protocol magic number.
Definition HandshakeHeader.hpp:39