# `XGW.Trunk.Frame`
[🔗](https://github.com/Lazarus404/xgw/blob/main/lib/xgw/trunk/frame.ex#L1)

Multiplex header for inter-edge trunk UDP payloads.

## What problem this solves

One trunk pipe carries RTP, RTCP, and opaque datachannel bytes. A single
leading type byte keeps demux cheap without WebRTC/ICE on the SFU-to-SFU path.

## RFCs

None directly; RTP/SRTP payloads inside follow RFC 3550 / RFC 3711.

# `kind`

```elixir
@type kind() :: :rtp | :rtcp | :dc
```

# `decode`

```elixir
@spec decode(binary()) :: {:ok, kind(), binary()} | {:error, :bad_frame}
```

Decodes a multiplex frame. Returns `{:ok, kind, payload}` or `{:error, :bad_frame}`.

# `decode_dc`

```elixir
@spec decode_dc(binary()) :: {:ok, binary(), binary()} | {:error, :bad_dc}
```

Unpacks a datachannel frame body.

# `encode`

```elixir
@spec encode(kind(), binary()) :: binary()
```

Encodes `kind` and `payload` as `<<type, payload::binary>>`.

# `encode_dc`

```elixir
@spec encode_dc(binary(), binary()) :: binary()
```

Packs an opaque datachannel frame body: `<<label_len::16, label::binary, data::binary>>`.

---

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