AirPlay.V2.TLV (AirPlay v0.2.0)

Copy Markdown View Source

TLV8 encoding for AirPlay 2 / HomeKit pairing (/pair-setup, /pair-verify).

Each item is [type:u8][len:u8][value]; values longer than 255 bytes are split into consecutive items of the SAME type (≤255 each) and concatenated on decode. An empty value encodes as [type][0]. Matches the AirPlay 2 TLV8 framing.

Types come from TLVType: :method(0) :identifier(1) :salt(2) :public_key(3) :proof(4) :encrypted_data(5) :state(6) :error(7) :signature(10) :flags(19).

Summary

Functions

The numeric code for a TLV type atom (or passes an integer through).

Decode TLV8 into a map %{type_atom => value_binary}, merging consecutive same-type items. Unknown type codes are kept as integers.

Encode an ordered list of {type, value} pairs to TLV8. type is an atom (or int); value a binary (ints 0..255 are accepted as a single byte).

Functions

code(t)

@spec code(atom() | non_neg_integer()) :: non_neg_integer()

The numeric code for a TLV type atom (or passes an integer through).

decode(data)

@spec decode(binary()) :: %{required(atom() | non_neg_integer()) => binary()}

Decode TLV8 into a map %{type_atom => value_binary}, merging consecutive same-type items. Unknown type codes are kept as integers.

encode(items)

@spec encode([{atom() | non_neg_integer(), binary() | 0..255}]) :: binary()

Encode an ordered list of {type, value} pairs to TLV8. type is an atom (or int); value a binary (ints 0..255 are accepted as a single byte).