View Source OSC.Types.String (ex_osc v0.1.0)
Encoding and decoding of the OSC string type.
There's minimal encoding and decoding required here, since the only
requirement for an OSC string is that it end with a null byte ("\0"
) and
that it be 32-bit aligned (like all OSC types). As such, encoding just
involves adding null bytes, and decoding just involves finding the last block
and removing the trailing nulls.
Link to this section Summary
Functions
Decodes an OSC string to an Elixir string.
Encodes an Elixir string to an OSC string type.
Returns ?s
, the type tag for the OSC integer type
Link to this section Types
@type t() :: binary()
An OSC string, represented by an Elixir binary string
Link to this section Functions
Decodes an OSC string to an Elixir string.
Will search through the input data for a 32-bit (4-byte) block that ends with
a null character ("\0"
), raising if it reaches the end without finding one.
Returns {string, rest}
, where string
is all data prior to the first null
in the final block, and rest
is a binary containing data after that block.
examples
Examples
iex> "goodbye world" |> OSC.Types.String.decode()
{"goodbye", "world"}
iex> "unaligned rest" |> OSC.Types.String.decode()
{"unaligned", "rest"}
iex> "nulblock after" |> OSC.Types.String.decode()
{"nulblock", "after"}
Encodes an Elixir string to an OSC string type.
Returns the encoded string, which will be the original string with 1 to 4
null bytes ("\0"
) added as needed (to 32-bit align it).
The input string cannot itself contain any null bytes.
examples
Examples
iex> "hello world" |> OSC.Types.String.encode()
<<"hello world", 0>>
iex> "PadMe" |> OSC.Types.String.encode()
<<"PadMe", 0, 0, 0>>
iex> "multiple of four" |> OSC.Types.String.encode()
<<"multiple of four", 0, 0, 0, 0>>
Returns ?s
, the type tag for the OSC integer type
iex> <<OSC.Types.String.type_tag()>>
"s"