Rebus.Decoder (rebus v0.3.0)

View Source

Decodes D-Bus wire data into Elixir values.

Multiple top-level values, arrays, and structs are represented as lists. Dictionary entries are {key, value} tuples, so dictionaries decode as lists of pairs. Variants are {signature, value} tuples. See the D-Bus type system for the signature grammar and wire layout. D-Bus infinities decode as :infinity/:negative_infinity; all NaNs decode as :nan, canonically losing their wire sign and payload.

Summary

Functions

Decodes wire data according to signature.

Decodes data and returns the number of bytes consumed.

Types

endianness()

@type endianness() :: :little | :big

Functions

decode(signature, data, endianness \\ :little)

@spec decode(binary(), binary(), endianness()) :: [any()]

Decodes wire data according to signature.

endianness is :little by default. The result is a list with one value for each top-level type in the signature.

Raises

Raises ArgumentError for an invalid signature, for a boolean whose wire value is neither 0 nor 1, and for non-zero alignment padding, Rebus.ResourceLimitError when the signature or data exceeds a local nesting, structural, or scalar-array limit, and Rebus.ProtocolLimitError when a declared array length exceeds Rebus.Message.max_array_size/0.

Examples

iex> Rebus.Decoder.decode("i", <<42, 0, 0, 0>>)
[42]

iex> Rebus.Decoder.decode("(si)", <<5, 0, 0, 0, "hello", 0, 0, 0, 42, 0, 0, 0>>)
[["hello", 42]]

decode_with_position(signature, data, endianness \\ :little)

@spec decode_with_position(binary(), binary(), endianness()) ::
  {[any()], non_neg_integer()}

Decodes data and returns the number of bytes consumed.

This is useful for callers that need to verify that a signature accounts for every byte in a bounded frame.

D-Bus infinities are represented by atoms and NaNs by canonical :nan. Raises Rebus.ResourceLimitError when a local structural or scalar-array limit is exceeded, and Rebus.ProtocolLimitError when a declared array length exceeds Rebus.Message.max_array_size/0.

Example

iex> Rebus.Decoder.decode_with_position("y", <<7, 99>>)
{[7], 1}