Class MsgPackFraming
- Namespace
- ShapeShift.MsgPack
- Assembly
- ShapeShift.MsgPack.dll
The length-prefixed framing that MsgPackSerializer's frame helpers read and write.
public static class MsgPackFraming
- Inheritance
-
MsgPackFraming
- Inherited Members
Remarks
MessagePack values are self-delimiting, so a stream of concatenated values needs no framing at all; that is what DeserializeAllAsync<T>(PipeReader, long, CancellationToken) reads. Framing earns its keep when a transport needs to know a message's extent before anything parses it: to hand a whole message off to another component, to reject an implausibly large message without decoding it, to skip a message whose contract the receiver does not implement, or to interleave MessagePack with other content on one connection.
A frame is a LengthPrefixByteCount-byte big-endian unsigned length, followed by exactly that many bytes, which must contain exactly one complete MessagePack value. A reader rejects a frame whose declared length exceeds the caller's limit before buffering any of it, rejects a stream that ends inside a frame, and rejects frame content that is not exactly one value.
Fields
DefaultMaxFrameLength
The default maximum frame length, in bytes, that the frame helpers accept.
public const long DefaultMaxFrameLength = 67108864
Field Value
Remarks
A length prefix is attacker-controlled input: it is read before any of the frame's content arrives, so an unbounded reader would wait for (and buffer) as much as the prefix claims. Callers that legitimately exchange larger messages should raise this deliberately.
LengthPrefixByteCount
The number of bytes in a frame's big-endian unsigned length prefix.
public const int LengthPrefixByteCount = 4