tlv

What is TLV (tag-length-value)?


What is TLV?

To put hooks (functions) in the code instead of if/else?

If I have one piece of code running on different platforms, at different places in code, I can put TLV function hooks to identify what platform I am on and do accordingly? Or something like that?

Benefits can be cleaner code? Easy to maintain? When a new platform is added, only TLV code needs to change and not the source code?

I may be completely wrong here.


Solution

  • TLV is Tag-length-value encoding. Often it is better referred to by it's original name, type-length-value.

    The first field is the "type" of data being processed, the second field specifies the "length" of the value, the third field contains a "length" amount of data representing the value for the "type".

    Multiple pieces of data can be transmitted in the same message by appending more triplets to a previously existing message.

    There's a page on wikipedia covering it in just a little more detail. Don't get confused though, each triplet is a "top level" description, there is typically no nesting of items in TLV (although you could come up with a way to do so by encoding TLV triplets in the V of another tag).