# `Sml.Decoder`
[🔗](https://github.com/emischorr/sml_ex/blob/v0.1.0/lib/sml/decoder.ex#L1)

Turns the generic terms produced by `Sml.Parser` into `Sml.Message` structs.

Message bodies are recognized by their tag. Bodies with an unknown tag or an
unexpected shape are returned as `{:unknown, tag, terms}` instead of failing
the whole telegram.

# `error`

```elixir
@type error() ::
  {:parse_error, reason :: term(), offset :: non_neg_integer()} | :invalid_crc
```

# `decode_body`

```elixir
@spec decode_body(Sml.Parser.term_t()) :: Sml.Message.body()
```

Decodes a parsed message body (`[tag, body]`) into its struct.

# `decode_message`

```elixir
@spec decode_message(binary(), keyword()) ::
  {:ok, Sml.Message.t(), binary()} | {:error, term(), binary()}
```

Decodes a single message from the beginning of `data`.

# `decode_messages`

```elixir
@spec decode_messages(binary(), keyword()) ::
  {:ok, [Sml.Message.t()]} | {:error, error()}
```

Decodes all messages in `payload` (the unwrapped content of a telegram).

## Options

  * `:crc` - checksum algorithm to verify: `:auto` (default, X-25 or
    Kermit), `:x25`, `:kermit`, or `false` to skip the check

---

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