Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::net::PacketHeader Struct Reference

Header at the start of every UDP datagram. More...

#include <aegis2d/net/packet.hpp>

Public Member Functions

bool operator== (const PacketHeader &) const =default
 Field-by-field equality.
 

Public Attributes

PacketType type = PacketType::Heartbeat
 What the datagram carries.
 
std::uint16_t sequence = 0
 Number of this datagram, incremented by the sender for each one and wrapping from 65535 to 0.
 
std::uint16_t ack = 0
 Most recent sequence number received from the peer.
 
std::uint32_t ack_bits = 0
 Bit n set: sequence ack - 1 - n was received too.
 
std::uint32_t session = 0
 Session token issued by the TCP login; 0 is never issued.
 
bool compressed = false
 Whether the payload is compressed (see aegis2d/net/compression.hpp).
 

Static Public Attributes

static constexpr std::uint32_t magic = 0x50595452
 First four bytes of every datagram: 52 54 59 50, "RTYP" in ASCII.
 
static constexpr std::uint8_t version = 1
 Protocol version; peers with another version are not understood.
 
static constexpr std::size_t size = 18
 Size of the header on the wire, in bytes.
 
static constexpr std::size_t max_payload_size = max_datagram_size - size
 Largest payload after the header.
 
static constexpr std::uint8_t compressed_flag = 0x80
 Bit of the type byte set when the payload is compressed.
 

Detailed Description

Header at the start of every UDP datagram.

On the wire: magic (u32), version (u8), type (u8), sequence (u16), ack (u16), ack_bits (u32), session (u32), little-endian, 18 bytes. The magic and the version are constants written by write_header() and checked by read_header(); the other fields are below. The type byte carries the type in its 7 low bits and compressed in its high bit.

Member Function Documentation

◆ operator==()

bool aegis2d::net::PacketHeader::operator== ( const PacketHeader &  ) const
default

Field-by-field equality.

Returns
true if every field is equal.

Member Data Documentation

◆ ack

std::uint16_t aegis2d::net::PacketHeader::ack = 0

Most recent sequence number received from the peer.

◆ ack_bits

std::uint32_t aegis2d::net::PacketHeader::ack_bits = 0

Bit n set: sequence ack - 1 - n was received too.

◆ compressed

bool aegis2d::net::PacketHeader::compressed = false

Whether the payload is compressed (see aegis2d/net/compression.hpp).

◆ compressed_flag

constexpr std::uint8_t aegis2d::net::PacketHeader::compressed_flag = 0x80
staticconstexpr

Bit of the type byte set when the payload is compressed.

◆ magic

constexpr std::uint32_t aegis2d::net::PacketHeader::magic = 0x50595452
staticconstexpr

First four bytes of every datagram: 52 54 59 50, "RTYP" in ASCII.

◆ max_payload_size

constexpr std::size_t aegis2d::net::PacketHeader::max_payload_size = max_datagram_size - size
staticconstexpr

Largest payload after the header.

◆ sequence

std::uint16_t aegis2d::net::PacketHeader::sequence = 0

Number of this datagram, incremented by the sender for each one and wrapping from 65535 to 0.

◆ session

std::uint32_t aegis2d::net::PacketHeader::session = 0

Session token issued by the TCP login; 0 is never issued.

◆ size

constexpr std::size_t aegis2d::net::PacketHeader::size = 18
staticconstexpr

Size of the header on the wire, in bytes.

◆ type

PacketType aegis2d::net::PacketHeader::type = PacketType::Heartbeat

What the datagram carries.

◆ version

constexpr std::uint8_t aegis2d::net::PacketHeader::version = 1
staticconstexpr

Protocol version; peers with another version are not understood.


The documentation for this struct was generated from the following file: