group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
PacketHeader.hpp File Reference

Wire format for the UDP transport layer. More...

#include <SDL3/SDL_stdinc.h>
#include <cstdint>
Include dependency graph for PacketHeader.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  net::PacketHeader
 16-byte header at the start of every UDP datagram we send. More...

Namespaces

namespace  net

Enumerations

enum class  net::PacketKind : uint8_t {
  net::Payload = 0 , net::ConnectionRequest = 1 , net::ConnectionAccepted = 2 , net::Disconnect = 3 ,
  net::KeepAlive = 4
}
 Packet kind discriminator (PacketHeader::kind field). More...
enum class  net::ChannelId : uint8_t {
  net::Unreliable = 0 , net::UnreliableSequenced = 1 , net::ReliableOrdered = 2 , net::ReliableUnordered = 3 ,
  net::Count = 4
}
 Per-channel reliability + ordering semantics. More...

Variables

constexpr uint16_t net::k_protocolMagic = 0x3247
 Magic bytes identifying our protocol. ASCII "G2" little-endian.
constexpr uint8_t net::k_protocolVersion = 1
 Wire-format version. Bump on any layout change.
constexpr int net::k_maxPacketBytes = 1200
 Maximum total UDP payload (header + data) in bytes.
constexpr int net::k_maxPayloadBytes = k_maxPacketBytes - static_cast<int>(sizeof(PacketHeader))
 Maximum payload bytes a single (non-fragmented) datagram can carry.

Detailed Description

Wire format for the UDP transport layer.

Phase 3d: every UDP datagram begins with this 16-byte header so the receiver can demux by channel, drop stale snapshots by sequence number, reassemble fragments, and route to the right connection.

Layout — 16 bytes, little-endian on the wire (matches all our target platforms; saves a byte-swap on send/recv).

0 1 2 3 4 5 6 7
+----+--+--+----------+--+--+----+
|magc| v|kn| connId |seq |
+----+--+--+-+--------+--+--+----+
8 9 10 11 12 13 14 15
+-+----+--+--+----+--+--+--+--+
|chan|flg| frag(idx, count) |
+----+--+--+--+----+--+--+--+
  • magic (u16): k_protocolMagic = 0x4732 ("G2"). Defends against stray UDP traffic from unrelated services landing on our port.
  • version (u8): bumped on incompatible wire-format changes.
  • kind (u8): PacketKind discriminator (handshake / data / etc).
  • connectionId (u32): server-assigned, identifies the peer. 0 in pre-handshake datagrams.
  • sequence (u16): per-(connection, channel) wrap-around counter. Receiver uses Glenn-Fiedler seq_more_recent to drop stale.
  • channel (u8): ChannelId — picks reliability + ordering rules.
  • flags (u8): bit 0 = fragmented; bit 1 = encrypted (future).
  • fragmentInfo (u16): hi 8 = fragment index, lo 8 = fragment count. 0 if not fragmented.

Stage 3d-1 ships only the struct + magic numbers; later stages populate sequence/channel/fragmentation as those features land.