Skip to main content

to_msgpack_vec

Function to_msgpack_vec 

Source
pub fn to_msgpack_vec<T: ToMessagePack>(value: &T) -> Result<Vec<u8>>
Expand description

Serializes a value of type T into a Vec<u8> containing its MessagePack representation.

§Errors

Serialization can fail if T’s implementation of ToMessagePack returns an error.

§Examples

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

fn main() {
    let point = Point { x: 1, y: 2 };
    let msgpack: Vec<u8> = zerompk::to_msgpack_vec(&point).unwrap();
    assert_eq!(msgpack, vec![0x92, 0x01, 0x02]);
}