Rebus.Encoder (rebus v0.3.0)
View SourceEncodes Elixir values using the D-Bus wire format.
Values must correspond to the supplied signature. See the
D-Bus type system
for the signature grammar and wire layout.
Double special values use :infinity, :negative_infinity, and :nan;
:nan encodes as a canonical quiet NaN.
Summary
Functions
Encodes a list of values for a D-Bus type signature.
Types
Functions
@spec encode(binary(), [any()], endianness()) :: iodata()
Encodes a list of values for a D-Bus type signature.
endianness is :little by default. The result is iodata; use
IO.iodata_to_binary/1 when a binary is required. Arrays and structs are
lists. Dictionary entries are {key, value} tuples, so dictionaries are
lists of pairs. Variants are {signature, value} tuples. Booleans are
true or false, and Unix file descriptors are non-negative indexes into
the descriptor list carried separately by a message.
Raises Rebus.ResourceLimitError when an encode operation exceeds the local
fixed-width scalar-array limit, and Rebus.ProtocolLimitError when an
encoded array exceeds Rebus.Message.max_array_size/0.
Examples
iex> Rebus.Encoder.encode("i", [42]) |> IO.iodata_to_binary()
<<42, 0, 0, 0>>
iex> Rebus.Encoder.encode("v", [{"s", "ready"}]) |> IO.iodata_to_binary()
<<1, "s", 0, 0, 5, 0, 0, 0, "ready", 0>>