View Source OSC.Types (ex_osc v0.1.1)
Encoding and decoding of the possible args
types in an OSC.Message
.
Encoded messages contain a "type tag string" (encoded as an OSC "string"
type), starting with a comma, where each subsequent letter indicates the type
of the respective argument. For example, ",sif"
indicates a message whose
three arguments are an OSC string, integer, and float, respectively.
Thus, to decode arguments, we need to know the type tag string; and when encoding arguments, we must also produce a type tag string.
Link to this section Summary
Functions
Decodes OSC arguments, given a decoded OSC type tag string.
Encode arguments into an OSC type tag string and encoded binaries.
Ensure that all arguments can be mapped to OSC types.
Link to this section Types
@type args() :: [t()]
List of OSC message arguments
@type t() :: OSC.Types.String.t() | OSC.Types.Integer.t() | OSC.Types.Float.t() | OSC.Types.Blob.t()
Values that can be encoded into OSC types
Link to this section Functions
Decodes OSC arguments, given a decoded OSC type tag string.
The type tag string will need to be decoded first using
OSC.Types.String.decode/1
. This function will then determine which type
decoder to use for each argument, based on the respective characters in the tag
string.
Returns {args, rest}
where args
is the decoded args and rest
is any
data that was not consumed by the argument decoders.
example
Example
iex> OSC.Types.decode_args(",iiis", <<
...> 0, 0, 0, 3,
...> 0, 0, 0, 2,
...> 0, 0, 0, 1,
...> "go", 0, 0,
...> "stop"
...> >>)
{[3, 2, 1, "go"], "stop"}
Encode arguments into an OSC type tag string and encoded binaries.
Returns {tags, encoded}
where tags
is the tag string, and encoded
is a
list of each encoded argument.
Note that the tag string will itself need to be encoded before sending, using
OSC.Types.String.encode/1
. The encoded tag string can then be concatenated
with the remaining binaries to form the argument portion of an OSC.Message
.
example
Example
iex> OSC.Types.encode_args([1.0, 2, [3], "4"])
{",fibs", [
<<63, 128, 0, 0>>, # float: 1.0
<<0, 0, 0, 2>>, # int: 2
<<0, 0, 0, 1, 3, 0, 0, 0>>, # blob: [3]
<<52, 0, 0, 0>> # string: "4"
]}
@spec validate_args(args()) :: :ok
Ensure that all arguments can be mapped to OSC types.
Raises ArgumentError
if an argument is of a type that cannot be encoded.
Note that this only serves as a basic sanity check on argument types, and does not actually ensure that arguments can be encoded. For example, it does not check the range of numeric types, nor does it check the contents of blobs.
examples
Examples
iex> OSC.Types.validate_args([1, 2.0, [3, 4, 5], "str"])
:ok
iex> OSC.Types.validate_args([1, :atom, 12])
** (ArgumentError) Unknown OSC type: :atom