Alternera.PluginWasmFramework.Runtime.Port.Protocol (alternera_plugin_wasm_framework v0.9.0)

Copy Markdown View Source

The frames between the node and alternera_wasm_host serve, over the port with {:packet, 4}. A frame is one tag byte and fixed little-endian fields, then bytes to its end. The framework's own frames (PluginWasmFramework.Frame) travel inside as bytes.

Node to host: H hello; L load (digest, pinned, the compiled file's path); U unload; C call (digest, flags, timeout ms, memory bytes, free bytes, export, input); R a host call's answer (1 and the reply, or 0: refused); B a body piece (1 and the bytes, or 0: no such body); G a growth answer (1 allowed, 0 refused); X cancel.

Host to node: h hello (protocol, Wasmtime version, target); l loaded (0 and whether _initialize is exported, or 1 and why not); c a host call (op, arg); b a body read (which, offset, length); g growth (the bytes wanted in all); r the result (outcome, the memory's size, then the reply or a trap's text).

The host speaks only to answer, and inside a call to ask: whoever owns the port reads every frame there is.

Summary

Functions

A frame from the host, decoded.

Decodes an h frame.

A host call's answer: the guest-facing reply, or a refusal.

Loads a compiled module into the port this process owns and waits for the answer, at most timeout ms. {:no_answer, reason} when none came in time: the host may still answer, so the process must not serve another call.

Sends frame; false when the port is closed (the host died, or was killed by another call on it).

The protocol version this side speaks.

Functions

body(bytes)

@spec body(binary() | :none) :: iodata()

call(raw, export, input, limits, free)

@spec call(binary(), String.t(), iodata() | :none, map(), non_neg_integer()) ::
  iodata()

cancel()

@spec cancel() :: binary()

decode(other)

@spec decode(binary()) ::
  {:host_call, String.t(), binary()}
  | {:body_read, :request | :response, non_neg_integer(), non_neg_integer()}
  | {:grow, non_neg_integer()}
  | {:result, atom(), non_neg_integer(), binary()}
  | {:loaded, boolean()}
  | {:load_failed, String.t()}
  | {:unknown, binary()}

A frame from the host, decoded.

decode_hello(arg1)

@spec decode_hello(binary()) ::
  {:ok,
   %{protocol: non_neg_integer(), wasmtime: String.t(), target: String.t()}}
  | :error

Decodes an h frame.

grow(bool)

@spec grow(boolean()) :: binary()

hello()

@spec hello() :: binary()

host_reply(reply)

@spec host_reply(iodata() | :refused) :: iodata()

A host call's answer: the guest-facing reply, or a refusal.

load(raw, pinned?, path)

@spec load(binary(), boolean(), Path.t()) :: iodata()

load_into(port, raw, pinned?, path, timeout \\ 30000)

@spec load_into(port(), binary(), boolean(), Path.t(), timeout()) ::
  :ok | {:error, String.t()} | {:no_answer, String.t()}

Loads a compiled module into the port this process owns and waits for the answer, at most timeout ms. {:no_answer, reason} when none came in time: the host may still answer, so the process must not serve another call.

send_frame(port, frame)

@spec send_frame(port(), iodata()) :: boolean()

Sends frame; false when the port is closed (the host died, or was killed by another call on it).

version()

@spec version() :: pos_integer()

The protocol version this side speaks.