Introducing waPC

WebAssembly Procedure Calls

waPC Icon
waPC Basic Interaction (Happy Path)
waPC Full Interaction
extern crate wapc;
use wapc::prelude::*;
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let module = load_file();
let mut host = WapcHost::new(&module)?;
wapc::set_host_callback(host_callback);
let res = host.call("wapc:sample!Hello", b"this is a test")?;
assert_eq!(res, b"hello world!");
Ok(())
}
fn host_callback(op: &str, payload: &[u8]) -> Result<Vec<u8>,
Box<dyn std::error::Error>> {
println!("Guest invoked '{}' with payload of {} bytes", op,
payload.len());
Ok(vec![])
}
extern crate wapc_guest as guest;
use guest::prelude::*;
wapc_handler!(handle_wapc);pub fn handle_wapc(operation: &str, msg: &[u8]) -> CallResult {
match operation {
"sample:Guest!Hello" => hello_world(msg),
_ => Err("bad dispatch".into()),
}
}
fn hello_world(
_msg: &[u8]) -> CallResult {
let _res = host_call("sample:Host!Call", b"hello")?;
Ok(vec![])
}

In relentless pursuit of elegant simplicity. Tinkerer, writer of tech, fantasy, and sci-fi. Converting napkin drawings into code for @CapitalOne

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store