std::encoding::msgpackMessagePack serialization.
Encode and decode values using the MessagePack binary format. Supports conversion between JSON strings and MessagePack bytes, as well as encoding individual typed values.
import std.encoding.msgpack;
fn main() {
let packed = msgpack.from_json("{\"x\": 1}") handle error {
println(f"operation failed: {error}");
return;
};
println(packed.len());
let json = msgpack.to_json(packed) handle error {
println(f"operation failed: {error}");
return;
};
println(json);
}
from_jsonEncode a JSON string to MessagePack binary.
Returns Err(reason) on invalid JSON or serialization failure. The codec's
own reason slot decides success, not the length of the result, so a
legitimately short encoding is never mistaken for a failure.
to_jsonDecode a MessagePack bytes buffer to a JSON string.
Returns Err(reason) on invalid input or deserialization failure.
encodeEncode any data value as MessagePack bytes. Records encode as objects keyed by field name in declaration order.
decodeDecode MessagePack bytes as T. A failure names the path of the value that did
not fit, for example Type: .tags[1]: expected string, found integer.