# `PhoenixWebTransport.Frame`
[🔗](https://github.com/knevan/phoenix-wtransport/blob/main/lib/phoenix_wtransport/frame.ex#L1)

Wire framing shared by the server session layer and the browser transport.

QUIC streams are byte streams, so every channel message is framed as

    <<length::32, type::8, payload::binary-size(length - 1)>>

where `type` is `0` for a text (JSON) message, `1` for a binary one, and `2`
for a pre-join `:auth` frame (`base64url.bearer.phx.<token>`).
The 32-bit length covers the type byte and the payload.

Each server-initiated unidirectional stream starts with a 4-byte lane id
before its first frame; see `PhoenixWebTransport.Lanes`.

# `decode_error`

```elixir
@type decode_error() ::
  :invalid_frame_length
  | {:frame_too_large, non_neg_integer(), non_neg_integer()}
  | {:invalid_frame_type, byte()}
```

# `frame`

```elixir
@type frame() :: {frame_type(), binary()}
```

# `frame_type`

```elixir
@type frame_type() :: :text | :binary | :auth
```

# `decode`

```elixir
@spec decode(binary(), keyword()) ::
  {:ok, [frame()], binary()} | {:error, decode_error()}
```

Decodes complete frames from `buffer`, returning `{:ok, frames, rest}` or
`{:error, reason}`.

Validates frame lengths (`len >= 1` and `len - 1 <= max_frame_size`) and type
bytes as soon as their header bytes arrive, before buffering oversized payloads.

Options:
  * `:max_frame_size` - maximum allowed payload bytes (default `16_777_216`).

# `decode!`

```elixir
@spec decode!(binary(), keyword()) :: {[frame()], binary()}
```

Bang variant of `decode/2` returning `{frames, rest}` or raising `ArgumentError`.

# `default_max_frame_size`

```elixir
@spec default_max_frame_size() :: pos_integer()
```

Default maximum frame payload size in bytes (16 MiB).

# `encode`

```elixir
@spec encode(frame_type(), iodata()) :: iodata()
```

Encodes a text, binary, or auth payload into a length-prefixed frame iodata.

---

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