Packet Contracts¶
Nalix.Common.Networking.Packets contains the core packet contracts shared by server and client code.
Source mapping¶
src/Nalix.Common/Networking/Packets/IPacket.cssrc/Nalix.Common/Networking/Packets/IPacketRegistry.cssrc/Nalix.Common/Networking/Packets/IPacketSender.cssrc/Nalix.Common/Networking/Packets/IPacketSequenced.cssrc/Nalix.Common/Networking/Packets/IPacketTimestamped.cssrc/Nalix.Common/Networking/Packets/IPacketReasoned.cs
Main types¶
IPacketIPacketRegistryIPacketSender<TPacket>
IPacket¶
IPacket is the base packet contract.
It includes:
- header-level metadata such as magic number, opcode, flags, priority, and protocol
LengthSerialize()overloads
This is the contract that packet implementations on both sides of the wire ultimately conform to.
IPacketRegistry¶
IPacketRegistry is the read-only packet catalog used to map incoming data to packet deserializers.
It supports:
- checking whether a magic number is known
- checking whether a packet type is registered
- deserializing raw bytes into
IPacket - retrieving a deserializer by magic number
IPacketSender¶
IPacketSender<TPacket> abstracts packet sending with metadata-aware transform behavior.
It supports:
- sending with normal metadata-driven behavior
- sending with an explicit encryption override
Example¶
IPacket packet = new PingRequest();
await sender.SendAsync((PingRequest)packet, ct);
if (registry.TryDeserialize(buffer, out IPacket? decoded))
{
Console.WriteLine($"decoded opcode: {decoded.OpCode}");
}