什么是 TLV(标签长度值)?
什么是TLV?
在代码中放置钩子(函数)而不是 if/else?
如果我有一段代码在不同平台、代码中的不同位置运行,我可以放置 TLV 函数挂钩来识别我所在的平台并执行相应操作吗?或者类似的东西?
好处是代码可以更干净?容易维护吗?添加新平台时,只需要更改TLV代码而不需要更改源代码?
我在这里可能完全错了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
TLV 是标签长度值编码。通常,最好通过其原始名称“类型-长度-值”来引用。
第一个字段是正在处理的数据的“类型”,第二个字段指定值的“长度”,第三个字段包含表示“类型”的值的“长度”数据量。
通过将更多的三元组附加到先前存在的消息,可以在同一消息中传输多条数据。
维基百科上有一个页面更详细地介绍了它。不过,请不要混淆,每个三元组都是“顶级”描述,TLV 中通常没有项目嵌套(尽管您可以想出一种方法,通过在另一个标签的 V 中编码 TLV 三元组来实现此目的)。
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).
TLV 是一种存储数据的方式,以便于快速解析该数据。
通常,您读取类型(标签)、长度和值,然后将这些数据发送到处理器功能。该处理器的唯一功能是处理类型 X。然后,您读取下一个类型、它的长度和值并将其发送到适当的处理器。
它通常用作处理数据的简单方法,而无需大量额外开销。
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.
我们仍然使用TLV来进行数据格式化。如果我们想向接收方发送数据,我们需要准备一个包含Tag-Length-Value数据的TLV包。
例如:
当我们想要发送它时,我们将这 3 行数据连接起来,如 DF 82 0A 03 30 31 32 。数据包可以包含大量这样的数据。
当接收方收到后,解析包非常容易,接收方可以顺利解析所有数据。
数据解析:
DF 82 0A
和DF 82 0B
是预先定义的(值类型 BCD、HEX、ASCII)标签。当数据到达时,在循环中,解析器首先会查找标签(即DF 82 0A
)和一个字节(数据长度)。它还将读取高达 length 的数据字节。We still use TLV for data formatting. And if we want to send data to receiver, we prepare a TLV package that is contain Tag-Length-Value data.
For example:
When we want to send it we concatenate this 3 row data like
DF 82 0A 03 30 31 32
. Data packages can contain lots of data like that.When receiver get it, parsing package is very easy and receiver can parse all of data smoothly.
Data Parsing:
DF 82 0A
andDF 82 0B
are pre-defined (value type BCD, HEX, ASCII) tags. When data arrived, in a loop, firstly parser will look for tag (i.e.DF 82 0A
) and one more byte (data length). It will also read data bytes up to length.TLV 指的是类型-长度-值三重奏中的编码值,此更通用的形式记录在维基百科。
在某些上下文(例如 EMV)中,TLV 指的是更具体的 X.690,维基百科上也有记录。
TLV 具有以下优点:
TLV 最大的缺点是它不是人类直接可读的。但请注意,如果数据转换为十六进制,则读取起来会比较困难。
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:
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.
我认为你所指的是类型 长度 值,并且有一个维基百科页面。希望有帮助。
I think what you are referring to is called Type Length Value, and there is a wikipedia page for it. Hope that helps.
TLV:标签-长度-值
示例:045002124354
如果我们以配置为例:045 的含义是
电视节目中的中奖号码:中奖号码的值为:12
TLV : tag - length - value
EXAMPLE : 045002124354
If we took as example that in the configuration : 045 is the meaning of the
winning number in a TV Show so : the value of the winning number is : 12