#serialize-deserialize #wapc #wasi #sdk #wasm-module

wapc-codec

A standard implementation of MessagePack serialization and deserialization for waPC communication

3 releases (stable)

1.1.0 Mar 23, 2023
1.0.0 Feb 10, 2022
1.0.0-alpha.0 Jan 21, 2022

#724 in WebAssembly

Download history 27/week @ 2024-07-14 28/week @ 2024-07-21 33/week @ 2024-07-28 15/week @ 2024-08-04 25/week @ 2024-08-11 28/week @ 2024-08-18 17/week @ 2024-08-25 28/week @ 2024-09-01 20/week @ 2024-09-08 17/week @ 2024-09-15 46/week @ 2024-09-22 28/week @ 2024-09-29 38/week @ 2024-10-06 17/week @ 2024-10-13 20/week @ 2024-10-20 17/week @ 2024-10-27

100 downloads per month
Used in wapc-guest

Apache-2.0

10KB
149 lines

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(())
}

Dependencies

~100–415KB