Data Preparation in TLV8

I am writing a HomeKit feature (possibly Bluetooth) in TLV8 format. Apple doc says

A value is an NSData object that contains a set of one or more TLV8s that are packed types of length values ​​with an 8-bit type, 8-bit length, and N-byte value.

According to Wikipeida string length value

A type

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

Length

Size of the value field (usually in bytes);

Value

A series of variable size bytes that contain data for this part of the message.

I do not know how to pack it. I suppose I can write raw bytes in NSData, but what do I write for the pad if I need any padding, etc. So, is there an example of how to do this?

+6
1

, . TLV8 : "Tag", "Length" "Value". , 8.

- UInt8. , , TLV8. - . - .

, 1 , :

let tag = 0x02 // For example
let length = 0x01
let value = 0x01
let data = Data(bytes: [tag, length, value]) // NSData
+2

Source: https://habr.com/ru/post/1017380/


All Articles