Skip to content

MessagePack (serde/msgpack)

MessagePack is a compact binary serialization format. It's significantly smaller than JSON in wire size and faster to parse since there's no text tokenization involved—just direct byte reading.

Modules

FilePurpose
encoder.vxStruct → binary MsgPack bytes
decoder.vxBinary MsgPack → Struct
value.vxMsgPackValue dynamic type tree
serde.vxContract-based Serializer/Deserializer implementations

When to Use

  • RPC and IPC: Inter-process communication where bandwidth matters.
  • Network Protocols: Custom binary protocols between Vex services.
  • Storage: Compact struct serialization for caching or databases.
  • High Throughput: When JSON text parsing overhead is unacceptable.

Encoding

rust
import { encode } from "serde/msgpack";

struct Sensor {
    id: i64
    temperature: f64
    active: bool
}

let data = Sensor { id: 42, temperature: 23.5, active: true };
let bytes = encode<Sensor>(&data);
// Compact binary: ~15 bytes vs ~50+ bytes in JSON

Decoding

rust
import { decode } from "serde/msgpack";

let! sensor = Sensor { };
decode<Sensor>(bytes, &sensor);
println("Sensor {sensor.id}: {sensor.temperature}°C");

Wire Format

MessagePack uses type-prefix bytes to encode values efficiently:

TypePrefixSize
Positive fixint0x00–0x7f1 byte
Negative fixint0xe0–0xff1 byte
fixstr0xa0–0xbf1 + N bytes
fixarray0x90–0x9f1 + elements
fixmap0x80–0x8f1 + entries
float640xcb9 bytes
int640xd39 bytes
true/false0xc3/0xc21 byte
nil0xc01 byte

Released under the MIT License.