Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
packet.hpp File Reference

Header carried by every UDP datagram, and the packet types. More...

#include <aegis2d/net/binary.hpp>
#include <aegis2d/net/export.hpp>
#include <cstddef>
#include <cstdint>
#include <string_view>
#include <variant>

Go to the source code of this file.

Classes

struct  aegis2d::net::PacketHeader
 Header at the start of every UDP datagram. More...
 

Namespaces

namespace  aegis2d
 Root namespace of the engine.
 
namespace  aegis2d::net
 Binary serialization, UDP/TCP sockets and the network thread.
 

Enumerations

enum class  aegis2d::net::PacketType : std::uint8_t {
  aegis2d::net::Connect = 1 , aegis2d::net::Accept = 2 , aegis2d::net::Input = 3 , aegis2d::net::Snapshot = 4 ,
  aegis2d::net::Event = 5 , aegis2d::net::Heartbeat = 6 , aegis2d::net::Disconnect = 7
}
 What a datagram carries; stored on one byte after the version. More...
 
enum class  aegis2d::net::HeaderError : std::uint8_t { aegis2d::net::Truncated , aegis2d::net::BadMagic , aegis2d::net::BadVersion , aegis2d::net::UnknownType }
 Why read_header() rejected a datagram. More...
 

Functions

std::string_view aegis2d::net::to_string (PacketType type) noexcept
 Name of a packet type, for logs.
 
std::string_view aegis2d::net::to_string (HeaderError error) noexcept
 Short description of a header error, for logs.
 
void aegis2d::net::write_header (BinaryWriter &writer, const PacketHeader &header)
 Writes the 18-byte header, magic and version included.
 
std::variant< PacketHeader, HeaderError > aegis2d::net::read_header (BinaryReader &reader) noexcept
 Reads and checks the header at the start of a datagram.
 

Variables

constexpr std::size_t aegis2d::net::max_datagram_size = 1200
 Largest UDP datagram the protocol sends or accepts, header included.
 

Detailed Description

Header carried by every UDP datagram, and the packet types.

Implements section 2 of the protocol RFC (docs/rfc/udp-header.md).