什么是 TLV(标签长度值)?

发布于 2024-10-07 01:48:50 字数 190 浏览 2 评论 0原文

什么是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

愛上了 2024-10-14 01:48:50

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

溺渁∝ 2024-10-14 01:48:50

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.

寄与心 2024-10-14 01:48:50

我们仍然使用TLV来进行数据格式化。如果我们想向接收方发送数据,我们需要准备一个包含Tag-Length-Value数据的TLV包。

例如:

Data Tag = DF 82 0A   
Data Length = 03  
Data Value =  30 31 32

当我们想要发送它时,我们将这 3 行数据连接起来,如 DF 82 0A 03 30 31 32 。数据包可以包含大量这样的数据。

当接收方收到后,解析包非常容易,接收方可以顺利解析所有数据。

数据解析:

数据:DF 82 0A 03 30 31 32 DF 82 0B 04 01 12 22 33

DF 82 0ADF 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:

Data Tag = DF 82 0A   
Data Length = 03  
Data Value =  30 31 32

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:

Data : DF 82 0A 03 30 31 32 DF 82 0B 04 01 12 22 33

DF 82 0A and DF 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.

不奢求什么 2024-10-14 01:48:50

TLV 指的是类型-长度-值三重奏中的编码值,此更通用的形式记录在维基百科

在某些上下文(例如 EMV)中,TLV 指的是更具体的 X.690,维基百科上也有记录

TLV 具有以下优点:

  • 编码格式相对紧凑
  • 解析相对简单(我在几个小时内编写了一个基本的 X.690 解析器)
  • X.690 TLV 支持嵌套类型(这部分解析起来稍微复杂一些,但是据我所知,这不是 EMV 所必需的)

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:

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

丑丑阿 2024-10-14 01:48:50

我认为你所指的是类型 长度 ,并且有一个维基百科页面。希望有帮助。

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

[旋木] 2024-10-14 01:48:50

TLV:标签-长度-值

示例:045002124354

如果我们以配置为例:045 的含义是
电视节目中的中奖号码:中奖号码的值为:12

  • TAG:搜索标签为:045
  • LENGTH:长度例如位于 3 位所以:002
  • VALUE:现在的值为:12(在2位置)

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

  • TAG : Search of the tag which is : 045
  • LENGTH : length for example is on 3 position so : 002
  • VALUE : Now the value is : 12 ( on 2 position )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文