Cobs v0.2.0 Cobs View Source

Elixir implementation of Consistent Overhead Byte Stuffing

Link to this section Summary

Functions

Decode COBS encoded binary (without 0 bytes) into a binary (with 0 bytes)

Decode COBS encoded binary (without 0 bytes) into a binary (with 0 bytes). Raise an ArgumentError on invalid input data

Encode a binary (with 0 bytes) into a COBS encoded binary (without 0 bytes)

Encode a binary (with 0 bytes) into a COBS encoded binary (without 0 bytes). Raise an ArgumentError on input data exceeding the allowed length (254 bytes)

Link to this section Functions

Link to this function decode(binary) View Source
decode(binary()) :: {:ok, binary()} | {:error | String.t()}

Decode COBS encoded binary (without 0 bytes) into a binary (with 0 bytes).

Example

iex> Cobs.decode(<<0x03, 0x01, 0x02, 0x02, 0x03>>)
{:ok, <<0x01, 0x02, 0x00, 0x03>>}
Link to this function decode!(binary) View Source
decode!(binary()) :: binary()

Decode COBS encoded binary (without 0 bytes) into a binary (with 0 bytes). Raise an ArgumentError on invalid input data.

Example

iex> Cobs.decode!(<<0x03, 0x01, 0x02, 0x02, 0x03>>)
<<0x01, 0x02, 0x00, 0x03>>
Link to this function encode(binary) View Source
encode(binary()) :: {:ok, binary()} | {:error | String.t()}

Encode a binary (with 0 bytes) into a COBS encoded binary (without 0 bytes).

Example

iex> Cobs.encode(<<0x01, 0x02, 0x00, 0x03>>)
{:ok, <<0x03, 0x01, 0x02, 0x02, 0x03>>}
Link to this function encode!(binary) View Source
encode!(binary()) :: binary()

Encode a binary (with 0 bytes) into a COBS encoded binary (without 0 bytes). Raise an ArgumentError on input data exceeding the allowed length (254 bytes)

Example

iex> Cobs.encode!(<<0x01, 0x02, 0x00, 0x03>>)
<<0x03, 0x01, 0x02, 0x02, 0x03>>