[][src]Crate wasi_binio_wasm

wasi_binio_host and wasi_binio_wasm

wasi_binio_wasm is the webassembly crate of wasm_binio. Another crate is wasi_binio_host which used in host. wasi_binio_host creates a call_stub so that host can call a webassembly function with complex data structure arguments and results. wasi_binio_wasm prepare the linear memory buffer and exports required wasm function so that the host can call.

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.

Functions

wasm_deserialize

Main function in wasm will call this function to deserialize the arguments to the prepared

wasm_prepare_buffer

Allocate buffer from wasm linear memory in order to let host to deserialize arguments into

wasm_serialize

Main function in wasm will call this function to deserialize the arguments to the prepared