1 unstable release
0.1.0 | Apr 2, 2020 |
---|
#80 in #results
8KB
wasi_binio_host and wasi_binio_wasm
wasi_binio_host
is the host crate of wasm_binio. Another crate is wasi_binio_wasm
which used in wasm module.
It creates a call_stub so that host can call a webassembly function with complex data structure arguments and results.
As of today, wasm function can only take i32 i64 f32 f64 types. If you have a function in wasm like this
In wasm: do_compute(point1: &Point, point2: &Point)->Rect {...}
there is no way to call it directly from host.
With the help from wasm_binio, we can instead call the call_stub function and send arguments and results like this
Code in host:
let result: Rect = call_stub(&instance, &(point1, point2), "do_compute")
Code in wasm:
#[no_mangle]
fn do_compute(ptr:i32, buffer_size: i32)->i64{
let point_tuple : (Point, Point) = wasi_binio_wasm::wasm_deserialize(ptr, buffer_size).unwrap();
let rect: Rect = some_how_make_a_rect_from_two_points()... /* Your own logic here */
wasi_binio_wasm::wasm_serialize(&rect).unwrap()
}
Since wasm and wasi are under active development. Wasi will soon provide complex arguments support.
At the time you find this crate, this feature probably have already been supported natively.
Dependencies
~30MB
~558K SLoC