Function from_slice_value

Source
pub fn from_slice_value<'facet, 'shape>(
    msgpack: &[u8],
    wip: &mut Partial<'facet, 'shape>,
) -> Result<(), Error<'shape>>
Expand description

Deserializes MessagePack-encoded data into a Facet value.

This function takes a MessagePack byte array and populates a Partial object according to the shape description, returning an Opaque value.

§Example

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

#[derive(Debug, Facet, PartialEq)]
struct User {
    id: u64,
    username: String,
}

// MessagePack binary data (equivalent to {"id": 42, "username": "user123"})
let msgpack_data = [
    0x82, 0xa2, 0x69, 0x64, 0x2a, 0xa8, 0x75, 0x73,
    0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0xa7, 0x75,
    0x73, 0x65, 0x72, 0x31, 0x32, 0x33
];

let user: User = from_slice(&msgpack_data).unwrap();
assert_eq!(user, User { id: 42, username: "user123".to_string() });

§Parameters

  • wip - A Partial object that will be filled with deserialized data
  • msgpack - A byte slice containing MessagePack-encoded data

§Returns

  • Ok(Opaque) containing the deserialized data if successful
  • Err(DecodeError) if an error occurred during deserialization

§MessagePack Format

This implementation follows the MessagePack specification: https://github.com/msgpack/msgpack/blob/master/spec.md