midi_proto v0.1.0 MidiProto.Firmata.String

Handles encoding and decoding strings (and binaries) using Firmata's two-byte encoding method.

Link to this section Summary

Functions

Decode two-byte sequences back into a binary

Encode binary values into two-byte sequences

Link to this section Functions

Link to this function

decode(value)

decode(value :: binary()) :: {:ok, binary()} | {:error, reason :: any()}

Decode two-byte sequences back into a binary:

Example

iex> <<0x4d, 0x00, 0x61, 0x00, 0x72, 0x00, 0x74, 0x00, 0x79, 0x00, 0x20, 0x00, 0x4d, 0x00, 0x63, 0x00, 0x46, 0x00, 0x6c, 0x00, 0x79, 0x00>>
...> |> decode()
{:ok, "Marty McFly"}
Link to this function

encode(value)

encode(value :: binary()) :: {:ok, binary()}

Encode binary values into two-byte sequences:

Example

iex> "Marty McFly"
...> |> encode()
{:ok, <<0x4d, 0x00, 0x61, 0x00, 0x72, 0x00, 0x74, 0x00, 0x79, 0x00, 0x20, 0x00, 0x4d, 0x00, 0x63, 0x00, 0x46, 0x00, 0x6c, 0x00, 0x79, 0x00>>}