Msgpack
Msgpack module: MessagePack binary serialization.
Encodes and decodes the MessagePack format (https://msgpack.org/). Compact binary alternative to JSON; supported by most languages.
Types: Value = Null | Bool(Bool) | Int(Int) -- 63-bit signed; see plan for range details | Str(String) -- UTF-8 bytes | Bin(List(Int)) -- raw bytes (values 0-255) | Array(List(Value)) | Map(List((Value, Value)))
Functions: encode(Value) -> List(Int) decode(List(Int)) -> Result(Value, String) decode_all(List(Int)) -> Result(List(Value), String) null/bool/int/str/bin/array/map -- convenience constructors
Note: Float is not supported in v1 (requires float_bits builtin). Note: encode returns List(Int); wrap with Bytes.from_list if needed.
Format byte constants (decimal): 192 = nil 194 = false 195 = true 196..198 = bin8/16/32 202..203 = float32/64 (unsupported) 204..207 = uint8/16/32/64 208..211 = int8/16/32/64 217..219 = str8/16/32 220..221 = array16/32 222..223 = map16/32 128..143 = fixmap 144..159 = fixarray 160..191 = fixstr 0..127 = pos fixint 224..255 = neg fixint
Types
Functions
Construct a MessagePack binary value from a list of byte ints (0-255).
Decode a MessagePack byte list to a Value. Returns Err if the input is empty, truncated, has trailing bytes, or contains an unsupported format byte (float, ext).
Msgpack.decode([192]) -- Ok(Null)
Msgpack.decode([42]) -- Ok(Int(42))
Msgpack.decode([195]) -- Ok(Bool(true))
Msgpack.decode([]) -- Err("unexpected end of input")Decode zero or more concatenated MessagePack values from bs. Returns Ok([]) on empty input. Useful for framing protocols.
Msgpack.decode_all([195, 42, 194])
-- Ok([Bool(true), Int(42), Bool(false)])Encode a Value to a list of bytes (0-255) in MessagePack format.
Msgpack.encode(Msgpack.Null) -- [192]
Msgpack.encode(Msgpack.Bool(true)) -- [195]
Msgpack.encode(Msgpack.Int(42)) -- [42]
Msgpack.encode(Msgpack.Str("hi")) -- [162, 104, 105]Construct a MessagePack map value from a list of (key, value) pairs.