libmsgpack encodes Oak values into MessagePack wire bytes.
MessagePack is a compact binary serialization format that is similar to JSON in structure but smaller and faster to parse on many workloads. Instead of text, it uses byte tags and packed payloads.
This module is focused on serialization output, either as:
- a byte string (for files/sockets)
- a packet list (
[0..255]integers) for inspection or transport adapters
msgpack := import('msgpack')
{ serialize: serialize, serializePacket: serializePacket } := import('msgpack')
Encodes value and returns a MessagePack byte string.
Returns :error when the value cannot be encoded by this implementation.
Encodes value and returns a MessagePack byte string.
If the value is unsupported, this falls back to MessagePack nil (0xC0).
Encodes value and returns a list of bytes ([int]) instead of a string.
Returns :error for unsupported values.
Converts a byte string to a byte list.
Converts a byte list to a byte string.
Wraps a byte string so it is encoded using MessagePack bin family (bin8,
bin16, bin32) instead of UTF-8 string tags.
Returns true when value is a Binary(...) wrapper object.
?->nilbool->true/falseint-> fixint/int8/int16/int32/uint8/uint16/uint32string-> fixstr/str8/str16/str32atom-> encoded as stringlist-> fixarray/array16/array32object-> fixmap/map16/map32 (keys encoded as strings)Binary(data)-> bin8/bin16/bin32
floatvalues are not encoded yet (serializeSafereturns:error)- integer support is currently bounded to signed 32-bit / unsigned 32-bit range
- map/object key order is not guaranteed
- no MessagePack deserializer yet
msgpack := import('msgpack')
raw := msgpack.serialize({ kind: 'ping', id: 7, ok: true })
packet := msgpack.packet(raw)
// packet starts with a map header and can be sent over sockets/files
msgpack := import('msgpack')
payload := '\x01\x02\x03\x04'
wrapped := msgpack.Binary(payload)
bytes := msgpack.serializePacket({ type: 'blob', data: wrapped })
msgpack := import('msgpack')
msgpack.serializeSafe(3.14) // => :error
msgpack.serialize(3.14) // => byte string [0xC0]
Serializes a list of values into MessagePack byte strings in parallel.
msgpack.pbatchSerialize([{a: 1}, {b: 2}, 'hello'])
Parses multiple MessagePack byte strings in parallel.
msgpack.pbatchParse([packed1, packed2])
// => [value1, value2]