OpenHAP::TLV(3p) Perl Library Manual OpenHAP::TLV(3p)

OpenHAP::TLV - TLV8 encoding/decoding for HAP protocol

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

This module implements TLV8 (Type-Length-Value with 8-bit fields) encoding and decoding as specified in the HomeKit Accessory Protocol.

Encodes a hash of type => value pairs into TLV8 format. Values longer than 255 bytes are automatically split into chunks.

Decodes TLV8 data into a hash of type => value pairs. Automatically concatenates chunks with the same type.

Returns the empty list if the buffer is malformed: a truncated record header, or a length field pointing past the end of the buffer.

spec/HAP-TLV8.md

2026-07-27 OpenBSD