Skip to main content

Module codec

Module codec 

Source
Expand description

Marshalling values to and from the D-Bus wire format.

Two rules account for nearly all of the difficulty:

  1. Every value is padded to its natural alignment, and the offset that alignment is measured against is the start of the message, not the start of the value being written. An encoder therefore has to carry a position, not just a buffer. (The body may be encoded from zero, because it always begins on an 8-byte boundary and every alignment divides 8.)

  2. The bytes carry no type tags. A u32 on the wire is four bytes and nothing else; only the signature says what it is. Decoding is therefore signature-directed, and a signature that disagrees with the bytes yields silent nonsense rather than an error — which is why Decoder bounds- checks every read instead of trusting lengths from the peer.

The exception is v, a variant, which carries its own signature inline. BlueZ wraps every property in one, so most real payloads are variants all the way down.

Structs§

Decoder
Reads values, signature-directed, bounds-checking every access.
Encoder
Writes values in little-endian, tracking position so padding is correct.

Enums§

CodecError
A malformed or unexpected message.