Crate facet_msgpack

Crate facet_msgpack 

Source
Expand description

MsgPack binary format for facet.

This crate provides serialization and deserialization for the MessagePack binary format.

§Serialization

use facet::Facet;
use facet_msgpack::to_vec;

#[derive(Facet)]
struct Point { x: i32, y: i32 }

let point = Point { x: 10, y: 20 };
let bytes = to_vec(&point).unwrap();

§Deserialization

There are two deserialization functions:

use facet::Facet;
use facet_msgpack::from_slice;

#[derive(Facet, Debug, PartialEq)]
struct Point { x: i32, y: i32 }

// MsgPack encoding of {"x": 10, "y": 20}
let bytes = &[0x82, 0xa1, b'x', 0x0a, 0xa1, b'y', 0x14];
let point: Point = from_slice(bytes).unwrap();
assert_eq!(point.x, 10);
assert_eq!(point.y, 20);

Both functions use Tier-2 JIT for compatible types (when the jit feature is enabled), with automatic fallback to Tier-0 reflection for all other types.

Structs§

MsgPackError
MsgPack parsing error.
MsgPackParser
MsgPack parser for deserialization.
MsgPackSerializeError
MsgPack serializer error.
MsgPackSerializer
MsgPack serializer.

Enums§

DeserializeError
Error produced by FormatDeserializer.

Functions§

from_slice
Deserialize a value from MsgPack bytes into an owned type.
from_slice_borrowed
Deserialize a value from MsgPack bytes, allowing zero-copy borrowing.
to_vec
Serialize a value to MsgPack bytes.
to_writer
Serialize a value to MsgPack bytes using a writer.