Protocol::HAP::TLV(3p) Perl Library Manual Protocol::HAP::TLV(3p)

Protocol::HAP::TLV - TLV8 encoder and decoder for the HAP protocol

    use Protocol::HAP::TLV;
    # Encode
    my $encoded = Protocol::HAP::TLV::encode(
        0x06 => pack('C', 1),  # State
        0x00 => pack('C', 0),  # Method
    );
    # Decode
    my %decoded = Protocol::HAP::TLV::decode($encoded);

This module encodes and decodes TLV8 (Type-Length-Value with 8-bit fields). The HomeKit Accessory Protocol specifies this format.

This function encodes a hash of type => value pairs into the TLV8 format. It automatically splits values that are longer than 255 bytes into chunks.

This function decodes TLV8 data into a hash of type => value pairs. It automatically concatenates the chunks that have the same type.

The function returns the empty list if the buffer is malformed. A malformed buffer has a truncated record header, or it has a length field that points past the end of the buffer.

spec/HAP-TLV8.md

2026-08-18 OpenBSD