Packet Metadata
On this page
Namespace: Nalix.Abstractions.Networking.Packets
Assembly: Nalix.Abstractions
PacketMetadata is an immutable readonly struct that stores the compiled handler attributes for a [PacketOpcode] method. It is instantiated once at startup by PacketHandlerGenerator and exposed on IPacketContext<TPacket>.Attributes.
Source Mapping
src/Nalix.Abstractions/Networking/Packets/PacketMetadata.csanalyzers/Nalix.Analyzers.Generators/PacketHandlerGenerator.cs
PacketMetadata Properties & Methods
| Member | Type | Description |
|---|---|---|
PacketOpcode | PacketOpcodeAttribute | The [PacketOpcode] attribute that binds the handler to its 16-bit wire opcode. |
Timeout | PacketTimeoutAttribute? | Optional [PacketTimeout] budget in milliseconds. |
Permission | PacketPermissionAttribute? | Optional [PacketPermission] level and evaluation mode. |
Encryption | PacketEncryptionAttribute? | Optional [PacketEncryption] requirement and cipher suite. |
RateLimit | PacketRateLimitAttribute? | Optional [PacketRateLimit] token-bucket / policy settings. |
Transport | PacketTransportAttribute? | Optional [PacketTransport] restriction (TCP, UDP, WEBSOCKET). |
CustomAttributes | IReadOnlyDictionary<Type, Attribute> | Dictionary of additional custom attributes discovered on the handler. |
GetCustomAttribute<TAttribute>() | TAttribute? | Retrieves a custom attribute of type TAttribute in $O(1)$ time without reflection. |
Compile-Time Generation
PacketHandlerGenerator inspects all attributes declared on each [PacketOpcode] method at compile time and constructs the PacketMetadata instance directly in <Controller>_PacketController.g.cs:
// Generated by PacketHandlerGenerator:
PacketMetadata metadata = new(
packetOpcode: new PacketOpcodeAttribute(0x3001),
timeout: new PacketTimeoutAttribute(5000),
permission: new PacketPermissionAttribute(PermissionLevel.USER, PermissionEvaluation.MinimumLevel),
encryption: new PacketEncryptionAttribute(true, CipherSuiteType.Chacha20Poly1305),
rateLimit: new PacketRateLimitAttribute(10, 3) { PolicyId = "chat-send" },
transport: new PacketTransportAttribute(NetworkTransport.TCP),
customAttributes: null);