Preparing data in TLV8

Viewed 1648

I'm writing a HomeKit (so perhaps Bluetooth) characteristic in TLV8 format. Apple doc says

The value is an NSData object containing a set of one or more TLV8's, which are packed type-length-value items with an 8-bit type, 8-bit length, and N-byte value.

According to Wikipeida a type-length value is

Type

A binary code, often simply alphanumeric, which indicates the kind of field that this part of the message represents;

Length

The size of the value field (typically in bytes);

Value

Variable-sized series of bytes which contains data for this part of the message.

I have no idea how to pack one. I suppose I can write raw bytes to NSData, but what do I write for pad, if I need any padding, etc. So is there an example of how to do that?

1 Answers
Related