# `Alternera.PluginWasmFramework.Frame`
[🔗](https://github.com/10e-ab/alternera-wasm/blob/v0.9.1/alternera_plugin_wasm_framework/lib/alternera/plugin_wasm_framework/frame.ex#L1)

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.

# `outputs`

```elixir
@type outputs() :: %{required(String.t()) =&gt; term()}
```

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

# `reply`

```elixir
@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`

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

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

# `decode_check`

```elixir
@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`

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

`text` as JSON, objects in their order.

# `decode_reply`

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

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

# `request`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
