PacketIo
static class
Provides static methods that decode an IncomingPacket into a concrete packet type.
Declaration
public static class PacketIo
| Namespace | McProtoNet.Protocol |
| Assembly | McProtoNet.Protocol.dll |
| Source | src/McProtoNet.Protocol/Flow/PacketIo.cs#L22 ↗ |
Remarks
IncomingPacket.Body belongs to the raw packet, which the caller disposes. Both entry
points decode immediately and return a packet that owns its data.
Only a broken or unsupported wire form is reported as a decode error. InvalidDataException,
EndOfStreamException, NbtFormatException, WrongLayerException
and PacketDecodeException map to DecodeError.Malformed, and
ProtocolNotSupportException maps to DecodeError.UnsupportedVersion. Any
other exception is not treated as a decode error and is propagated to the caller.
Methods
| Signature | Description |
|---|---|
static T Decode<T>(in IncomingPacket raw, int protocolVersion) where T : class, IPacket<T> | Decodes the body of the specified raw packet as the packet type T. |
static bool TryDecode<T>(in IncomingPacket raw, int protocolVersion, out T? packet, out DecodeError error) where T : class, IPacket<T> | Attempts to decode the body of the specified raw packet as the packet type T. |
Decode<T>(in IncomingPacket, int)
public static T Decode<T>(in IncomingPacket raw, int protocolVersion) where T : class, IPacket<T>
Decodes the body of the specified raw packet as the packet type T.
Parameters: raw (IncomingPacket), protocolVersion (int)
Returns: T - The decoded packet.
Exceptions: PacketDecodeException - The body is malformed. -or- The packet is not supported on protocolVersion. -or- The body was decoded but bytes remain unread.
TryDecode<T>(in IncomingPacket, int, out T?, out DecodeError)
public static bool TryDecode<T>(in IncomingPacket raw, int protocolVersion, out T? packet, out DecodeError error) where T : class, IPacket<T>
Attempts to decode the body of the specified raw packet as the packet type T.
A body that is decoded but leaves unread bytes is reported as
DecodeError.TrailingBytes.
Parameters: raw (IncomingPacket), protocolVersion (int), packet (T), error (DecodeError)
Returns: bool - true if the body was decoded; otherwise, false.