msgpack

MessagePack binary serialization - compact, fast, and schema-free.

Import

import msgpack

Functions

msgpack.encode(val: any) -> [int]

Encode an XS value to a MessagePack byte array.

msgpack.decode(bytes: [int]) -> any

Decode a MessagePack byte array back to an XS value.

msgpack.encode_stream(val: any) -> [int]

Encode a value to a streaming MessagePack byte array (suitable for appending multiple values).

msgpack.decode_stream(bytes: [int]) -> any

Decode from a streaming MessagePack byte sequence.

msgpack.size(val: any) -> int

Return the number of bytes the value would occupy when encoded, without allocating the output.

msgpack.roundtrip(val: any) -> any

Encode then decode a value in one call - useful for verifying serialization fidelity.

msgpack.benchmark(val: any, iters?: int) -> map

Benchmark encode/decode performance over a number of iterations. Returns a map with encode_ms, decode_ms, bytes, and iterations.

Low-level pack helpers

msgpack.pack_int(n), msgpack.pack_float(n), msgpack.pack_str(s) - encode a single primitive to a byte array. Useful when hand-building binary frames.

Examples

scratch.xs