Module wapc_codec::messagepack
source · [−]Expand description
The messagepack implementation Serialization/Deserialization functions for transmitting data to waPC hosts and guests as MessagePack bytes.
use serde::{Serialize, Deserialize};
use wapc_codec::messagepack::{serialize,deserialize};
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)]
struct Person {
first_name: String,
last_name: String,
age: u8,
}
let person = Person {
first_name: "Samuel".to_owned(),
last_name: "Clemens".to_owned(),
age: 49,
};
println!("Original : {:?}", person);
let bytes = serialize(&person).unwrap();
println!("Serialized messagepack bytes: {:?}", bytes);
let round_trip: Person = deserialize(&bytes).unwrap();
assert_eq!(person, round_trip);Functions
deserialize() converts a MessagePack-formatted list of bytes into the target data structure.
serialize() serializes a structure into MessagePack bytes.