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
Link to this section Functions
Link to this function
decode(value)
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"}
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>>}