Module std::encoding::msgpack

MessagePack 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.

Examples

import std::encoding::msgpack;
import std::encoding::hex;

fn main() {
    let packed = msgpack.from_json("{\"x\": 1}");
    println(packed.len());
    let json = msgpack.to_json(packed);
    println(json);
}

Contents

Functions

Function from_json

pub fn from_json(json: String) -> bytes

Encode a JSON string to MessagePack binary.

Returns an empty bytes buffer on invalid JSON.

Function to_json

pub fn to_json(data: bytes) -> String

Decode a MessagePack bytes buffer to a JSON string.

Returns an empty string on error.

Function encode_int

pub fn encode_int(val: i64) -> bytes

Encode an integer as a MessagePack varint.

Function encode_string

pub fn encode_string(s: String) -> bytes

Encode a string as MessagePack str.

Function encode_bytes

pub fn encode_bytes(data: bytes) -> bytes

Encode binary data as a MessagePack bin.