MidiProto.Firmata.String (midi_proto v0.2.0)

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

Summary

Functions

Decode two-byte sequences back into a binary

Encode binary values into two-byte sequences

Functions

@spec 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"}
@spec 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>>}