Skip to content

MessagePackDecoder

[Source]

Implements low-level decoding from the MessagePack serialization format.

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. If data may arrive incrementally, use MessagePackStreamingDecoder instead.

primitive val MessagePackDecoder

Constructors

create

[Source]

new val create()
: MessagePackDecoder val^

Returns


Public Functions

uint

[Source]

Decodes an unsigned integer from any uint or positive fixint format.

fun box uint(
  b: Reader ref)
: U64 val ?

Parameters

Returns


int

[Source]

Decodes a signed integer from any int, uint, or fixint format. Errors if a uint_64 value exceeds I64.max_value().

fun box int(
  b: Reader ref)
: I64 val ?

Parameters

Returns


array

[Source]

Reads an array header from any array format. Returns the element count. The caller must read that many elements afterward.

fun box array(
  b: Reader ref)
: U32 val ?

Parameters

Returns


map

[Source]

Reads a map header from any map format. Returns the pair count. The caller must read that many key-value pairs afterward.

fun box map(
  b: Reader ref)
: U32 val ?

Parameters

Returns


nil

[Source]

Returns nothing. Throws an error if the next byte isn't a MessagePack nil.

fun box nil(
  b: Reader ref)
: None val ?

Parameters

Returns


bool

[Source]

fun box bool(
  b: Reader ref)
: Bool val ?

Parameters

Returns


positive_fixint

[Source]

fun box positive_fixint(
  b: Reader ref)
: U8 val ?

Parameters

Returns

  • U8 val ?

negative_fixint

[Source]

fun box negative_fixint(
  b: Reader ref)
: I8 val ?

Parameters

Returns

  • I8 val ?

u8

[Source]

fun box u8(
  b: Reader ref)
: U8 val ?

Parameters

Returns

  • U8 val ?

u16

[Source]

fun box u16(
  b: Reader ref)
: U16 val ?

Parameters

Returns


u32

[Source]

fun box u32(
  b: Reader ref)
: U32 val ?

Parameters

Returns


u64

[Source]

fun box u64(
  b: Reader ref)
: U64 val ?

Parameters

Returns


i8

[Source]

fun box i8(
  b: Reader ref)
: I8 val ?

Parameters

Returns

  • I8 val ?

i16

[Source]

fun box i16(
  b: Reader ref)
: I16 val ?

Parameters

Returns


i32

[Source]

fun box i32(
  b: Reader ref)
: I32 val ?

Parameters

Returns


i64

[Source]

fun box i64(
  b: Reader ref)
: I64 val ?

Parameters

Returns


f32

[Source]

fun box f32(
  b: Reader ref)
: F32 val ?

Parameters

Returns


f64

[Source]

fun box f64(
  b: Reader ref)
: F64 val ?

Parameters

Returns


fixstr

[Source]

fun box fixstr(
  b: Reader ref)
: String iso^ ?

Parameters

Returns


str

[Source]

fun box str(
  b: Reader ref)
: String iso^ ?

Parameters

Returns


str_8

[Source]

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.

fun box str_8(
  b: Reader ref)
: String iso^ ?

Parameters

Returns


str_16

[Source]

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.

fun box str_16(
  b: Reader ref)
: String iso^ ?

Parameters

Returns


str_32

[Source]

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.

fun box str_32(
  b: Reader ref)
: String iso^ ?

Parameters

Returns


str_utf8

[Source]

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.

fun box str_utf8(
  b: Reader ref)
: String iso^ ?

Parameters

Returns


fixstr_utf8

[Source]

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().

fun box fixstr_utf8(
  b: Reader ref)
: String iso^ ?

Parameters

Returns


str_8_utf8

[Source]

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().

fun box str_8_utf8(
  b: Reader ref)
: String iso^ ?

Parameters

Returns


str_16_utf8

[Source]

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().

fun box str_16_utf8(
  b: Reader ref)
: String iso^ ?

Parameters

Returns


str_32_utf8

[Source]

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().

fun box str_32_utf8(
  b: Reader ref)
: String iso^ ?

Parameters

Returns


byte_array

[Source]

fun box byte_array(
  b: Reader ref)
: Array[U8 val] iso^ ?

Parameters

Returns


bin_8

[Source]

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.

fun box bin_8(
  b: Reader ref)
: Array[U8 val] iso^ ?

Parameters

Returns


bin_16

[Source]

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.

fun box bin_16(
  b: Reader ref)
: Array[U8 val] iso^ ?

Parameters

Returns


bin_32

[Source]

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.

fun box bin_32(
  b: Reader ref)
: Array[U8 val] iso^ ?

Parameters

Returns


fixarray

[Source]

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.

fun box fixarray(
  b: Reader ref)
: U8 val ?

Parameters

Returns

  • U8 val ?

array_16

[Source]

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.

fun box array_16(
  b: Reader ref)
: U16 val ?

Parameters

Returns


array_32

[Source]

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.

fun box array_32(
  b: Reader ref)
: U32 val ?

Parameters

Returns


fixmap

[Source]

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.

fun box fixmap(
  b: Reader ref)
: U8 val ?

Parameters

Returns

  • U8 val ?

map_16

[Source]

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.

fun box map_16(
  b: Reader ref)
: U16 val ?

Parameters

Returns


map_32

[Source]

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.

fun box map_32(
  b: Reader ref)
: U32 val ?

Parameters

Returns


ext

[Source]

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)

fun box ext(
  b: Reader ref)
: (U8 val , Array[U8 val] val) ?

Parameters

Returns


fixext_1

[Source]

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.

fun box fixext_1(
  b: Reader ref)
: (U8 val , Array[U8 val] val) ?

Parameters

Returns


fixext_2

[Source]

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.

fun box fixext_2(
  b: Reader ref)
: (U8 val , Array[U8 val] val) ?

Parameters

Returns


fixext_4

[Source]

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.

fun box fixext_4(
  b: Reader ref)
: (U8 val , Array[U8 val] val) ?

Parameters

Returns


fixext_8

[Source]

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.

fun box fixext_8(
  b: Reader ref)
: (U8 val , Array[U8 val] val) ?

Parameters

Returns


fixext_16

[Source]

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.

fun box fixext_16(
  b: Reader ref)
: (U8 val , Array[U8 val] val) ?

Parameters

Returns


ext_8

[Source]

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.

fun box ext_8(
  b: Reader ref)
: (U8 val , Array[U8 val] val) ?

Parameters

Returns


ext_16

[Source]

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.

fun box ext_16(
  b: Reader ref)
: (U8 val , Array[U8 val] val) ?

Parameters

Returns


ext_32

[Source]

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.

fun box ext_32(
  b: Reader ref)
: (U8 val , Array[U8 val] val) ?

Parameters

Returns


timestamp

[Source]

fun box timestamp(
  b: Reader ref)
: (I64 val , U32 val) ?

Parameters

Returns


skip

[Source]

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.

fun box skip(
  b: Reader ref)
: None val ?

Parameters

Returns


eq

[Source]

fun box eq(
  that: MessagePackDecoder val)
: Bool val

Parameters

Returns


ne

[Source]

fun box ne(
  that: MessagePackDecoder val)
: Bool val

Parameters

Returns