msgpack
stableEncode and decode values using the MessagePack binary serialization format, with a pure-Rust implementation supporting all standard types.
use plugin msgpack::{encode, decode, encode_string, …} Functions (9)
- encode Encode any value to MessagePack bytes
- decode Decode MessagePack bytes to a value
- encode_string Encode a single string to MessagePack bytes
- decode_to_string Decode MessagePack bytes and convert to string
- encode_integer Encode an integer with optimal int format
- encode_number Encode a float as MessagePack float64
- encode_bool Encode a boolean to MessagePack bytes
- encode_nil Encode nil (0xc0) to MessagePack bytes
- encode_bin Wrap raw bytes in MessagePack bin format
Encode any value to MessagePack bytes
Encodes any Zolo value — nil, bool, int, float, string, bytes, or table — into MessagePack binary format. Tables with consecutive integer keys starting at 1 are encoded as arrays; all other tables become maps.
use plugin msgpack::{encode, decode}
let data = #{"name": "Alice", "age": 30}
let bytes = encode(data)
let back = decode(bytes)
print(back["name"])
Decode MessagePack bytes to a value
Decodes a MessagePack byte sequence back into a Zolo value. Arrays become tables with integer keys; maps become tables with their original keys preserved.
use plugin msgpack::{encode, decode}
let original = [1, 2, 3, 4, 5]
let packed = encode(original)
let unpacked = decode(packed)
print(unpacked[3])
Encode a single string to MessagePack bytes
Encodes a single string value using the most compact MessagePack string format (fixstr for strings up to 31 bytes, str8/str16/str32 otherwise).
use plugin msgpack::{encode_string}
let b = encode_string("hello")
print("encoded {b} bytes")
Decode MessagePack bytes and convert to string
Decodes MessagePack bytes and coerces the result to a string. Useful when you know the packed value is a scalar and want it as text without further type inspection.
use plugin msgpack::{encode_string, decode_to_string}
let b = encode_string("world")
let s = decode_to_string(b)
print(s)
Encode an integer with optimal int format
Encodes an integer using the smallest possible MessagePack int format (positive fixint, uint8/16/32/64, or signed int8/16/32/64).
use plugin msgpack::{encode_integer, decode}
let b = encode_integer(255)
let v = decode(b)
print(v)
Encode a float as MessagePack float64
Encodes a floating-point number as a MessagePack float64 (8-byte big-endian IEEE 754).
use plugin msgpack::{encode_number, decode}
let b = encode_number(3.14159)
let v = decode(b)
print(v)
Encode a boolean to MessagePack bytes
Encodes a boolean as a 1-byte MessagePack value (0xc3 for true, 0xc2 for false).
use plugin msgpack::{encode_bool, decode}
let b = encode_bool(true)
let v = decode(b)
print(v)
Encode nil (0xc0) to MessagePack bytes
Returns the single-byte MessagePack nil value 0xc0. Useful when building binary protocols that require an explicit nil token.
use plugin msgpack::{encode_nil, decode}
let b = encode_nil()
let v = decode(b)
print(v)
Wrap raw bytes in MessagePack bin format
Wraps a raw byte sequence in the MessagePack bin format (bin8, bin16, or bin32 depending on size). Use this when you need to distinguish binary data from string data in your encoded messages.
use plugin msgpack::{encode_bin, decode}
let raw = [0x01, 0x02, 0x03]
let b = encode_bin(raw)
let v = decode(b)
print(v)