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

Header that starts every packet sent on an open connection. More...

#include <protocol/PacketHeader.hpp>

Public Member Functions

bool serialize (PacketWriter &writer) const
 Writes the header in network byte order.
 
bool deserialize (PacketReader &reader)
 Reads the header from a buffer.
 

Public Attributes

std::uint32_t connectionId = 0
 Connection the packet belongs to.
 
std::uint32_t sequence = 0
 Sequence number of this packet.
 
std::uint32_t ack = 0
 Latest sequence received from the peer.
 
std::uint32_t ackBits = 0
 Bitfield of the 32 previous sequences.
 

Static Public Attributes

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

Detailed Description

Header that starts every packet sent on an open connection.

Offset Size Field Description
0 4 connectionId Id given by the server in Welcome.
4 4 sequence Sequence number of this packet.
8 4 ack Latest sequence received from the peer.
12 4 ackBits Bit i set if ack - 1 - i was received.

Member Function Documentation

◆ serialize()

bool PacketHeader::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 PacketHeader::deserialize ( PacketReader & reader)

Reads the header from a buffer.

Parameters
readerSource buffer.
Returns
True on success, false if fewer than 16 bytes remain.