Skip to main content

Module codec

Module codec 

Source
Expand description

The Wire trait and the struct layouts msgspec uses.

msgspec encodes a Struct in one of two layouts, both mirrored here by [wire_struct!]:

  • array (array_like=True): [tag?, field, ...] in declaration order. Declaration order is the wire contract, so fields are only ever appended. A shorter array takes the remaining fields’ defaults; a longer one has its extra trailing elements ignored. A tagged struct (tag=True) starts with its class name.
  • map: {name: value, ...} with every field present, in declaration order. Unknown keys are ignored and missing keys take their defaults.

Both layouts fail when a field without a default is absent.

Structs§

Dict
A Python dict: a msgpack map whose entries keep their wire order.

Enums§

StrOrList
A Python str | list[str] field.

Traits§

Wire
A type with a msgpack encoding shared with the Python side.

Functions§

decode_bytes
Decode a message that is a single msgpack buffer.
decode_frames
Decode a message from its frames, failing on bytes after the value.
encode_frames
Encode a value as a message: the msgpack buffer, then its out-of-band frames.