NAME

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

SYNOPSIS

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);

DESCRIPTION

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

FUNCTIONS

encode(%items)

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.

decode($data)

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.

SEE ALSO

spec/HAP-TLV8.md