6#include <aegis2d/net/export.hpp>
54 static constexpr std::uint32_t
magic = 0x50595452;
56 static constexpr std::uint8_t
version = 1;
58 static constexpr std::size_t
size = 18;
70 std::uint16_t
ack = 0;
111[[nodiscard]] AEGIS2D_NET_EXPORT std::variant<PacketHeader, HeaderError>
Little-endian binary serialization with bounds-checked reads, for network packets.
Reads values written by BinaryWriter from untrusted bytes, never past their end.
Definition binary.hpp:88
Writes values field by field into a growing byte buffer.
Definition binary.hpp:21
Binary serialization, UDP/TCP sockets and the network thread.
Definition binary.hpp:14
std::variant< PacketHeader, HeaderError > read_header(BinaryReader &reader) noexcept
Reads and checks the header at the start of a datagram.
PacketType
What a datagram carries; stored on one byte after the version.
Definition packet.hpp:22
@ Input
Client to server: the player's input state for one tick.
@ Disconnect
Both ways: the sender leaves the session.
@ Connect
Client to server: binds the client's UDP endpoint to its session.
@ Heartbeat
Both ways: keeps the session alive and carries acknowledgements when there is nothing else to send.
@ Event
Both ways: gameplay events that must arrive (spawn, death...), resent until acknowledged.
@ Accept
Server to client: the endpoint is bound, gameplay traffic may start.
@ Snapshot
Server to client: the state of the world.
void write_header(BinaryWriter &writer, const PacketHeader &header)
Writes the 18-byte header, magic and version included.
std::string_view to_string(PacketType type) noexcept
Name of a packet type, for logs.
constexpr std::size_t max_datagram_size
Largest UDP datagram the protocol sends or accepts, header included.
Definition packet.hpp:17
HeaderError
Why read_header() rejected a datagram.
Definition packet.hpp:84
@ Truncated
Fewer than PacketHeader::size bytes.
@ BadVersion
Another protocol version.
@ UnknownType
The type byte, its compressed flag aside, is not a PacketType.
@ BadMagic
The first four bytes are not PacketHeader::magic: not our protocol.