# `Meshcore.Frame`
[🔗](https://github.com/nyannus/meshcore_ex/blob/v0.1.0/lib/meshcore/frame.ex#L1)

Stream framing used by the serial and TCP transports.

Frames sent to the device are `0x3C | length (u16 LE) | payload`; frames
coming from the device are `0x3E | length (u16 LE) | payload`. The decoder is
resilient against garbage on the line (some radios interleave console
output on the same UART): it resynchronises on the next `0x3E` byte and
drops frames announcing more than 300 bytes.

# `t`

```elixir
@type t() :: %Meshcore.Frame{buffer: binary()}
```

# `decode`

```elixir
@spec decode(t(), binary()) :: {[binary()], t()}
```

Feeds a chunk of received bytes; returns the completed frame payloads (in
order) and the new decoder state.

    iex> {frames, _} = Meshcore.Frame.decode(Meshcore.Frame.new(), <<0x3E, 2, 0, 0xAA, 0xBB, 0x3E, 1>>)
    iex> frames
    [<<0xAA, 0xBB>>]

# `encode`

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

Wraps `payload` into an outgoing frame.

# `new`

```elixir
@spec new() :: t()
```

Creates an empty decoder state.

---

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