Function hdk::prelude::host_call

source ·
pub fn host_call<I, O>(
    f: unsafe extern "C" fn(_: u32, _: u32) -> u64,
    input: I
) -> Result<O, WasmError>where
    I: Serialize + Debug,
    O: DeserializeOwned + Debug,
Expand description

Given an extern that we expect the host to provide:

  • Serialize the payload by reference
  • Write the bytes into a new allocation on the guest side
  • Call the host function and pass it the pointer and length to our leaked serialized data
  • The host will consume and deallocate the bytes
  • Deserialize whatever bytes we can import from the host after calling the host function
  • Return a Result of the deserialized output type O