wapc-codec

Crates.iowapc-codec
lib.rswapc-codec
version1.1.0
sourcesrc
created_at2022-01-21 23:39:25.084535
updated_at2023-03-23 14:33:48.033343
descriptionA standard implementation of MessagePack serialization and deserialization for waPC communication
homepagehttps://wapc.io
repository
max_upload_size
id518801
size23,885
Jarrod Overson (jsoverson)

documentation

https://docs.rs/wapc-codec-messagepack

README

waPC messagepack codec

crates.io license

This crates contains common serialization and deserialization methods for communicating in and out of waPC modules.

waPC does not require MessagePack but it does require a communication contract between hosts and guests. The waPC CLI code generator uses this crate but you are free to use what you want.

Example

The following is a simple example of synchronous, bi-directional procedure calls between a WebAssembly host runtime and the guest module.

use serde::{Deserialize, Serialize};
use wapc_codec::messagepack::{deserialize, serialize};

#[derive(Deserialize, Serialize, Debug)]
struct Person {
  first_name: String,
  last_name: String,
  age: u8,
}

pub fn main() -> Result<(), Box<dyn std::error::Error>> {
  let person = Person {
    first_name: "Samuel".to_owned(),
    last_name: "Clemens".to_owned(),
    age: 49,
  };

  println!("Original : {:?}", person);

  let bytes = serialize(&person)?;

  println!("Serialized messagepack bytes: {:?}", bytes);

  let round_trip: Person = deserialize(&bytes)?;

  println!("Deserialized : {:?}", round_trip);

  Ok(())
}
Commit count: 0

cargo fmt