Alternera.PluginWasmFramework.Frame (alternera_plugin_wasm_framework v0.9.0)

Copy Markdown View Source

The frames of guest interface version 0 (c_src/alternera_guest.h), the host's side. A field is a 32-bit little-endian length and that many bytes.

  • The request frame alternera_run gets: the source as a field, then the env, a JSON object, to the end (request/2). Bodies are not in it: the guest reads them through alternera.body_read.
  • The reply frame it answers: a status byte, a flags byte and four fields, a, b, c and outputs (decode_reply/1), whose meaning depends on the status.
  • A host call's answer: 0 and the operation's JSON answer, or 1 and two fields, the error's type and its message (the runtime writes it from what the host function gave).
  • What alternera_check answers: a JSON array of {"line", "message"} (decode_check/1).

JSON objects in a returned value or in outputs are decoded as Jason.OrderedObject, keeping the order the script built them in, as Script's ordered JSON does.

Summary

Types

The named values a script set in outputs: name to JSON value.

A returned value: the raw bytes of a string, or a JSON value.

Functions

What alternera_check answered: :ok, or the problems as {line, message} (line nil when the guest named none).

text as JSON, objects in their order.

A reply frame read back, or {:error, why} for one that is not well formed.

The request frame for source and env (a map JSON can encode).

Types

outputs()

@type outputs() :: %{required(String.t()) => term()}

The named values a script set in outputs: name to JSON value.

reply()

@type reply() ::
  {:returned, value(), String.t() | nil, outputs()}
  | {:nothing, outputs()}
  | {:failed, String.t(), String.t(), pos_integer() | nil, outputs()}
  | {:script_error, String.t(), pos_integer() | nil, outputs()}
  | :allocation_refused
  | {:invalid_result, String.t(), outputs()}
  | {:host_error, String.t(), String.t(), outputs()}

value()

@type value() :: {:raw, binary()} | {:json, term()}

A returned value: the raw bytes of a string, or a JSON value.

Functions

decode_check(json)

@spec decode_check(binary()) :: :ok | {:error, [{pos_integer() | nil, String.t()}]}

What alternera_check answered: :ok, or the problems as {line, message} (line nil when the guest named none).

decode_json(text)

@spec decode_json(binary()) :: {:ok, term()} | {:error, String.t()}

text as JSON, objects in their order.

decode_reply(arg1)

@spec decode_reply(binary()) :: reply() | {:error, String.t()}

A reply frame read back, or {:error, why} for one that is not well formed.

request(source, env)

@spec request(String.t(), map()) :: {:ok, iodata()} | {:error, String.t()}

The request frame for source and env (a map JSON can encode).