Sml.Decoder (SmlEx v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

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

Decodes a single message from the beginning of data.

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

Types

error()

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

Functions

decode_body(other)

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

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

decode_message(data, opts \\ [])

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

Decodes a single message from the beginning of data.

decode_messages(payload, opts \\ [])

@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