Перейти к основному содержимому

PacketFlow

static class

Generated dispatcher. Packets whose codegen is still stubbed are not dispatched — they fall through to Unknown instead of throwing inside the receive loop. Trailing bytes raise a hook, not an exception: the packet already reached the visitor, but the spec is suspect. Three doors onto the same table: Dispatch (throws on a malformed body), TryDispatch (same visitor, a false + reason instead of the throw) and TryDecode (visitor-free — hands back the decoded packet itself).

Declaration

public static class PacketFlow
NamespaceMcProtoNet.Protocol
AssemblyMcProtoNet.Protocol.dll
Sourcesrc/McProtoNet.Protocol/Generated/Flow/PacketFlow.g.cs#L14 ↗

Methods

SignatureDescription
static void Dispatch<TVisitor>(in IncomingPacket raw, int protocolVersion, PacketPhase phase, PacketDirection dir, ref TVisitor visitor) where TVisitor : IPacketVisitor-
static bool TryDecode(in IncomingPacket raw, int protocolVersion, PacketPhase phase, PacketDirection direction, out IPacket? packet, out DecodeError error)One raw packet in, one decoded packet out — no visitor to write.
static bool TryDispatch<TVisitor>(in IncomingPacket raw, int protocolVersion, PacketPhase phase, PacketDirection direction, ref TVisitor visitor, out DecodeError error) where TVisitor : IPacketVisitorDispatch that survives a malformed body: returns false with <code class="paramref">error</code> filled where PacketFlow.Dispatch<TVisitor> would let the exception out.

Dispatch<TVisitor>(in IncomingPacket, int, PacketPhase, PacketDirection, ref TVisitor)

public static void Dispatch<TVisitor>(in IncomingPacket raw, int protocolVersion, PacketPhase phase, PacketDirection dir, ref TVisitor visitor) where TVisitor : IPacketVisitor

Parameters: raw (IncomingPacket), protocolVersion (Int32), phase (PacketPhase), dir (PacketDirection), visitor (<TVisitor>)

TryDecode(in IncomingPacket, int, PacketPhase, PacketDirection, out IPacket?, out DecodeError)

public static bool TryDecode(in IncomingPacket raw, int protocolVersion, PacketPhase phase, PacketDirection direction, out IPacket? packet, out DecodeError error)

One raw packet in, one decoded packet out — no visitor to write. An id this (phase, direction) cannot map yields an UnknownPacket and still returns true: an unmapped id is a normal stream condition, not an error. A malformed body returns false with <code class="paramref">error</code> filled and <code class="paramref">packet</code> null. The allocation-free hot path is PacketFlow.Dispatch<TVisitor> / PacketFlow.TryDispatch<TVisitor>; this door costs nothing extra either — packets are classes, so the capture is a reference, not a box.

Parameters: raw (IncomingPacket), protocolVersion (Int32), phase (PacketPhase), direction (PacketDirection), packet (IPacket), error (DecodeError)

Returns: Boolean

TryDispatch<TVisitor>(in IncomingPacket, int, PacketPhase, PacketDirection, ref TVisitor, out DecodeError)

public static bool TryDispatch<TVisitor>(in IncomingPacket raw, int protocolVersion, PacketPhase phase, PacketDirection direction, ref TVisitor visitor, out DecodeError error) where TVisitor : IPacketVisitor

Dispatch that survives a malformed body: returns false with <code class="paramref">error</code> filled where PacketFlow.Dispatch<TVisitor> would let the exception out. True means the packet reached the visitor — including the normal stream condition of an id this (phase, direction) has no mapping for, which reaches Unknown exactly as in PacketFlow.Dispatch<TVisitor>. Trailing bytes stay a hook, not a failure. Only a failure of the body read is converted, and only the kinds a decoder may swallow (see TryClassify): cancellation, a stubbed decoder and out-of-memory still propagate. An exception thrown by the visitor itself is never converted — the table lowers reading before it calls the visitor, so the consumer's own bugs come out as themselves.

Parameters: raw (IncomingPacket), protocolVersion (Int32), phase (PacketPhase), direction (PacketDirection), visitor (<TVisitor>), error (DecodeError)

Returns: Boolean

Events

SignatureDescription
static event TrailingBytesHook? OnTrailingBytes-

OnTrailingBytes

public static event TrailingBytesHook? OnTrailingBytes

Returns: TrailingBytesHook