Crate holochain_wasmer_guestsource ·
Wrapper types to enable optimized handling of
unidiomatic way to derive default trait implementations of TryFrom in/out of SerializedBytes
A simple macro to wrap
return_err_ptrin an analogy to the native rust
Helper macro for returning an error from a WASM.
A Canonical Serialized Bytes representation for data If you have a data structure that needs a canonical byte representation use this Always round-trip through SerializedBytes via. a single TryFrom implementation. This ensures that the internal bytes of SerializedBytes are indeed canonical. The corrolary is that if bytes are NOT wrapped in SerializedBytes we can assume they are NOT canonical. Typically we need a canonical serialization when data is to be handled at the byte level by independently implemented and maintained systems.
UnsafeBytes the only way to implement a custom round trip through bytes for SerializedBytes It is intended to be an internal implementation in TryFrom implementations The assumption is that any code using UnsafeBytes is NOT valid messagepack data This allows us to enforce that all data round-tripping through SerializedBytes is via TryFrom and also allow for custom non-messagepack canonical representations of data types.
Wraps a WasmErrorInner with a file and line number. The easiest way to generate this is with the
wasm_error!macro that will insert the correct file/line and can create strings by forwarding args to the
Enum of all possible ERROR states that wasm can encounter.
A data structure that can be deserialized from any data format supported by Serde.
A data structure that can be serialized into any data format supported by Serde.
Simple and safe type conversions that may fail in a controlled way under some circumstances. It is the reciprocal of
An attempted conversion that consumes
self, which may or may not be expensive.
Receive arguments from the host. The guest sets the type
Othat the host needs to match. If deserialization fails then a
WasmError::Deserializeis returned. The guest should immediately return an
Errback to the host. The
WasmError::Deserializeenum contains the bytes that failed to deserialize so the host can unambiguously provide debug information.
Given an extern that we expect the host to provide:
u32, return a
DoubleUSizemerged. Works via a simple bitwise shift to move the pointer to high bits then OR the length into the low bits.
GuestPtrLenas best we can. This is not necessarily straightforward as the serialization process can error recursively. In the worst case we can’t even serialize an enum variant, in which case we panic. The casts from
u32are safe as long as the guest code is compiled for
Convert any serializable value into a
GuestPtrthat can be returned to the host. The host is expected to know how to consume and deserialize it.
Given 2x merged
usize, split out two
usize. Performs the inverse of
WasmSizethat points to a position in wasm linear memory that the host and guest are sharing to communicate across function calls.
Enough bits to fit a pointer and length into so we can return it. The externs defined as “C” don’t support multiple return values (unlike wasm). The native Rust support for wasm externs is not stable at the time of writing.
WasmSizeinteger that represents the size of bytes to read/write to memory.
usizefor wasm. Wasm has a memory limit of 4GB so offsets and lengths fit in