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.

share | edit
 
 
It has nothing to do with code and everything to do with data. –   Karl Knechtel  Dec 11 '10 at 0:02
 
@karl: ( I know this is an old thread, but somehow I landed here today again :) ) Are you sure that this has nothing to do with code? Because I guess its other way around - all about code and nothing about data. :D –   hari  Apr 15 '11 at 18:26
add comment

4 Answers

up vote 10  down vote accepted

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

share | edit
 
 
Thanks Edwin. I was looking for exact need and pros/cons of it. If you know of any example, let me know. –   hari  Dec 11 '10 at 7:44
 
The pros are that it's a dead simple format (easy to parse, you can skip new added fields in old programs). The cons are that it's a dead simple format (no built-in hierarchy support, encodes binary poorly, data type must be known to both sides beforehand or transmitted in some custom-encoded way, very poor support for when the data changes over time are not additive but are substitutions, etc). Some of these cons are fixable, like you can uuencode binary to transmit it, but that's just more work to de-uuencode on the other end. –   Edwin Buck  Dec 13 '10 at 15:20
 
Actually you can put more TLVs inside other TLVs: the 6th bit of the 1st byte of type field in the TLV structure, if set to 1, means constructed, which indicates that the v part of the TLV structure is actually a set of other TLVs. –   Fabio A.  Sep 24 '13 at 13:36
1 
Fabio, yes you can embed TLVs in TLVs, as my original post mentioned; however, there is not a standard for which byte needs to be set unless you go with something a bit more specific than TLV, like X.690 BER encoding, or something. With the mentioned encoding, it is the 6th byte of the class sub-field of the tag that flags a constructed value, not the first byte of the type field. So obviously there is not an accepted constructed tag flag, without selecting amongst many different "more specific" TLV like protocols. –   Edwin Buck  Sep 24 '13 at 18:07
add comment

TLV refers to encoding values in Type-Length-Value trio's, and this more general form is documented on WikiPedia.

In some context's (such as EMV) TLV refers to the more specific X.690 which is also documented on WikiPedia.

TLV has the following advantages:

  • Relatively compact encoding format
  • Relatively simple to parse (I wrote a basic X.690 parser in a couple of hours)
  • The X.690 TLV has support for nested types (this part is slightly more complicated to parse, but from what I can tell is not required for EMV)

TLV's biggest disadvantage is that it is not directly human readable. Note however if the data is converted to hex it is only moderately difficult to read.

share | edit
 
 
add comment

TLV is a way of storing data to facilitate quick parsing of that data.

Typically, you read the type(tag), length and value and then send those datum to a processor function. This processor functions only function will be to process type X. Then, you read the next type, it's length and value and send it to the appropriate processor.

It's typically used as an easy way to process data without a lot of extra overhead.

share | edit
 
 
C'mon people, when you downvote, tell me why (especially 2 years after the fact) –   KevinDTimm  Dec 18 '12 at 2:42
add comment

I think what you are referring to is called Type Length Value, and there is a wikipedia page for it. Hope that helps.

share | edit
 
 
add comment
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值