A few times in my career I've found myself writing decoders for responses from IoT products or weird apis that insted of using JSON or XML as a response, they reply with something like HC010410290203123, and they provide certain documentation to explain that...

HC 01 04 1029 02 03 123
HC = This segment's name
01 = field name (explained in documentation, example: 'User id')
04 = field length (in this case, 4 characters)
1029 = field value (in this case, user id is 1029)
02 = field name (explained in documentation, example: 'User code')
03 = field length (in this case, 3 characters)
123 = field value (in this case, user code is 123)

And so on, and so on. I've encountered this kind of encoding about 4 to 5 times in my career and now that I got a new assignment that works just like this, I've been wondering, does this have a name?


Type-Length-Value or Tag-Length-Value.

Both protocols describe a mechanism for encoding optional information in multiple tuplets of variable length into text-based messages, using three fields: type, length and value. The type and length are fixed in size (typically 1-4 bytes), and the value field is of variable size. These fields are used as follows:


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


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


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

The format allows flexibility, in that you can have as many messages containing as many different data types and sizes as are required, so long as they are supported by the message specification.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.