MessagePackZeroCopyDecoder¶
Implements low-level zero-copy decoding from the MessagePack serialization format.
This decoder mirrors MessagePackDecoder but takes a
ZeroCopyReader instead of a buffered.Reader. Variable-length
values (strings, binary data, extensions) are returned as val
views into the reader's internal buffer rather than freshly
allocated copies. Fixed-size values (integers, floats, booleans)
are decoded identically to MessagePackDecoder.
You should be familiar with how MessagePack encodes messages if
you use this API directly. There are very few guardrails
preventing you from incorrectly decoding documents. This is
particularly true when using the array and map format family
decoding methods, which only read headers — the caller must read
each element individually afterward.
Two styles of decode methods are provided:
- Compact methods (
uint,int,str,byte_array,ext,array,map) peek at the format byte to determine the wire format and accept any format within the family. - Format-specific methods (
u8,u16,str_8,str_16,bin_8,fixext_1,ext_8, etc.) validate a single expected format byte, then read the data directly. Use these when you know the exact wire format in advance.
This decoder assumes all data is available when decoding begins.
For streaming use, MessagePackStreamingDecoder uses zero-copy
decoding internally.
Constructors¶
create¶
Returns¶
Public Functions¶
uint¶
Decodes an unsigned integer from any uint or positive fixint format.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U64 val ?
int¶
Decodes a signed integer from any int, uint, or fixint format. Errors if a uint_64 value exceeds I64.max_value().
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- I64 val ?
array¶
Reads an array header from any array format. Returns the element count. The caller must read that many elements afterward.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U32 val ?
map¶
Reads a map header from any map format. Returns the pair count. The caller must read that many key-value pairs afterward.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U32 val ?
nil¶
Returns nothing. Throws an error if the next byte isn't a MessagePack nil.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- None val ?
bool¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- Bool val ?
positive_fixint¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U8 val ?
negative_fixint¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- I8 val ?
u8¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U8 val ?
u16¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U16 val ?
u32¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U32 val ?
u64¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U64 val ?
i8¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- I8 val ?
i16¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- I16 val ?
i32¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- I32 val ?
i64¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- I64 val ?
f32¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- F32 val ?
f64¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- F64 val ?
fixstr¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- String val ?
str¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- String val ?
str_8¶
Decodes a MessagePack str 8 value. Validates that the format byte is str_8 (0xD9), then reads the 1-byte length prefix and data.
Errors if the format byte does not match or if insufficient
data is available. For a method that accepts any string wire
format, use str() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- String val ?
str_16¶
Decodes a MessagePack str 16 value. Validates that the format byte is str_16 (0xDA), then reads the 2-byte length prefix and data.
Errors if the format byte does not match or if insufficient
data is available. For a method that accepts any string wire
format, use str() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- String val ?
str_32¶
Decodes a MessagePack str 32 value. Validates that the format byte is str_32 (0xDB), then reads the 4-byte length prefix and data.
Errors if the format byte does not match or if insufficient
data is available. For a method that accepts any string wire
format, use str() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- String val ?
str_utf8¶
Decodes a MessagePack str value using the smallest matching format, then validates that the bytes are valid UTF-8.
Errors if the format byte is not a str type, if insufficient
data is available, or if the decoded bytes are not valid
UTF-8. On a UTF-8 validation error the bytes have already
been consumed from the reader. For the non-validating
variant, use str(). To retain access to the raw bytes on
validation failure, use str() followed by
MessagePackValidateUTF8.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- String val ?
fixstr_utf8¶
Decodes a MessagePack fixstr value, then validates that the bytes are valid UTF-8.
Errors if the format byte does not match, if insufficient
data is available, or if the decoded bytes are not valid
UTF-8. For the non-validating variant, use fixstr().
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- String val ?
str_8_utf8¶
Decodes a MessagePack str 8 value, then validates that the bytes are valid UTF-8.
Errors if the format byte does not match, if insufficient
data is available, or if the decoded bytes are not valid
UTF-8. For the non-validating variant, use str_8().
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- String val ?
str_16_utf8¶
Decodes a MessagePack str 16 value, then validates that the bytes are valid UTF-8.
Errors if the format byte does not match, if insufficient
data is available, or if the decoded bytes are not valid
UTF-8. For the non-validating variant, use str_16().
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- String val ?
str_32_utf8¶
Decodes a MessagePack str 32 value, then validates that the bytes are valid UTF-8.
Errors if the format byte does not match, if insufficient
data is available, or if the decoded bytes are not valid
UTF-8. For the non-validating variant, use str_32().
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- String val ?
byte_array¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
bin_8¶
Decodes a MessagePack bin 8 value. Validates that the format byte is bin_8 (0xC4), then reads the 1-byte length prefix and data.
Errors if the format byte does not match or if insufficient
data is available. For a method that accepts any bin wire
format, use byte_array() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
bin_16¶
Decodes a MessagePack bin 16 value. Validates that the format byte is bin_16 (0xC5), then reads the 2-byte length prefix and data.
Errors if the format byte does not match or if insufficient
data is available. For a method that accepts any bin wire
format, use byte_array() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
bin_32¶
Decodes a MessagePack bin 32 value. Validates that the format byte is bin_32 (0xC6), then reads the 4-byte length prefix and data.
Errors if the format byte does not match or if insufficient
data is available. For a method that accepts any bin wire
format, use byte_array() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
fixarray¶
Reads a header for a MessgePack "fixarray". This only reads the header. The number of array items returned by this method needs to be read via other methods after this is called.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U8 val ?
array_16¶
Reads a header for a MessgePack "array_16". This only reads the header. The number of array items returned by this method needs to be read via other methods after this is called.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U16 val ?
array_32¶
Reads a header for a MessgePack "array_32". This only reads the header. The number of array items returned by this method needs to be read via other methods after this is called.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U32 val ?
fixmap¶
Reads a header for a MessgePack "fixmap". This only reads the header. The number of map items returned by this method needs to be read via other methods after this is called.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U8 val ?
map_16¶
Reads a header for a MessgePack "map_16". This only reads the header. The number of map items returned by this method needs to be read via other methods after this is called.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U16 val ?
map_32¶
Reads a header for a MessgePack "map_32". This only reads the header. The number of map items returned by this method needs to be read via other methods after this is called.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- U32 val ?
ext¶
Allows for the reading of user supplied extensions to the MessagePack format.
fixext * types return a tuple representing:
(user supplied type indentifier, data byte array)
Parameters¶
- b: ZeroCopyReader ref
Returns¶
fixext_1¶
Decodes a MessagePack fixext 1 value. Validates that the format byte is fixext_1 (0xD4), then reads the ext type byte and 1 byte of data.
Returns (ext_type, data). Errors if the format byte does
not match. For a method that accepts any ext wire format, use
ext() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
fixext_2¶
Decodes a MessagePack fixext 2 value. Validates that the format byte is fixext_2 (0xD5), then reads the ext type byte and 2 bytes of data.
Returns (ext_type, data). Errors if the format byte does
not match. For a method that accepts any ext wire format, use
ext() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
fixext_4¶
Decodes a MessagePack fixext 4 value. Validates that the format byte is fixext_4 (0xD6), then reads the ext type byte and 4 bytes of data.
Returns (ext_type, data). Errors if the format byte does
not match. For a method that accepts any ext wire format, use
ext() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
fixext_8¶
Decodes a MessagePack fixext 8 value. Validates that the format byte is fixext_8 (0xD7), then reads the ext type byte and 8 bytes of data.
Returns (ext_type, data). Errors if the format byte does
not match. For a method that accepts any ext wire format, use
ext() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
fixext_16¶
Decodes a MessagePack fixext 16 value. Validates that the format byte is fixext_16 (0xD8), then reads the ext type byte and 16 bytes of data.
Returns (ext_type, data). Errors if the format byte does
not match. For a method that accepts any ext wire format, use
ext() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
ext_8¶
Decodes a MessagePack ext 8 value. Validates that the format byte is ext_8 (0xC7), then reads the 1-byte length prefix, ext type byte, and data.
Returns (ext_type, data). Errors if the format byte does
not match. For a method that accepts any ext wire format, use
ext() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
ext_16¶
Decodes a MessagePack ext 16 value. Validates that the format byte is ext_16 (0xC8), then reads the 2-byte length prefix, ext type byte, and data.
Returns (ext_type, data). Errors if the format byte does
not match. For a method that accepts any ext wire format, use
ext() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
ext_32¶
Decodes a MessagePack ext 32 value. Validates that the format byte is ext_32 (0xC9), then reads the 4-byte length prefix, ext type byte, and data.
Returns (ext_type, data). Errors if the format byte does
not match. For a method that accepts any ext wire format, use
ext() instead.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
timestamp¶
Parameters¶
- b: ZeroCopyReader ref
Returns¶
skip¶
Advances past one complete MessagePack value without decoding it. For containers (arrays and maps), skips all contained elements.
Errors if insufficient data is available or if the format byte is invalid (0xC1). On error, no bytes are consumed.
This method has no limit on the number of values
traversed. For protection against container amplification
attacks, use MessagePackStreamingDecoder.skip which
enforces a configurable max_skip_values limit.
Parameters¶
- b: ZeroCopyReader ref
Returns¶
- None val ?
eq¶
Parameters¶
- that: MessagePackZeroCopyDecoder val
Returns¶
- Bool val
ne¶
Parameters¶
- that: MessagePackZeroCopyDecoder val
Returns¶
- Bool val