R-Type 0.1
Loading...
Searching...
No Matches
HandshakeHeader Struct Reference

Header of the datagrams exchanged before a connection exists. More...

#include <protocol/HandshakeHeader.hpp>

Public Member Functions

bool serialize (PacketWriter &writer) const
 Writes the header in network byte order.
 
bool deserialize (PacketReader &reader)
 Reads and validates the magic number and handshake type.
 

Public Attributes

std::uint32_t magic = MAGIC
 Protocol magic number.
 
std::uint8_t version = VERSION
 Protocol version.
 
HandshakeType type = HandshakeType::Hello
 Handshake step.
 

Static Public Attributes

static constexpr std::size_t HEADER_SIZE = 6
 Encoded size of the header, in bytes.
 

Detailed Description

Header of the datagrams exchanged before a connection exists.

Offset Size Field Description
0 4 magic Always 0x52545950.
4 1 version Protocol version, currently 1.
5 1 type A HandshakeType value.

A Welcome datagram is followed by the 4 byte connection id.

Member Function Documentation

◆ serialize()

bool HandshakeHeader::serialize ( PacketWriter & writer) const

Writes the header in network byte order.

Parameters
writerDestination buffer.
Returns
True on success, false if the buffer is full.

◆ deserialize()

bool HandshakeHeader::deserialize ( PacketReader & reader)

Reads and validates the magic number and handshake type.

Parameters
readerSource buffer.
Returns
True if a valid header was read, false otherwise.