【问题标题】:Encoding a data structure based on TLV encoding基于 TLV 编码对数据结构进行编码
【发布时间】:2013-02-14 05:30:08
【问题描述】:

我必须根据 X.690 编码对存在于数据结构中的参数进行编码。 假设,我的结构是:

struct Data_Struct
{
   parameter1
   parameter2
   parameter3
}

其中部分或全部参数可能包含有效数据,例如 parameter1parameter3。 然后我应该只使用 TLV 编码对 parameter1parameter3 进行编码。 我是否必须遵循顺序程序才能遵循这一点。喜欢,

Check whether parameter 1 is present
    If present, find the tag of the parameter from a lookup table and encode it
Check whether parameter 2 is present
    If present, find the tag of the parameter from a lookup table and encode it
Check whether parameter 3 is present
    If present, find the tag of the parameter from a lookup table and encode it
  • 由于程序是重复的,我可以模块化吗?
  • 最好的方法是什么?
  • 有没有办法按顺序访问参数?
  • 我怎样才能在参数和它的标签之间建立关系?

值的长度是可变的。

【问题讨论】:

    标签: c++ encoding tlv


    【解决方案1】:

    您需要创建一个包含成对成员和标签的表,例如{&Data_Struct::parameter1, TagForParam1}。这是不可避免的,因为编译器无法猜测该标签。

    您还需要定义您认为“空”或“有效数据”的内容。这可能取决于类型。例如。 +INF 是一个有效的浮点值吗?所以,添加重载函数bool IsValid(T)

    您现在可以编写一个通用例程遍历表,检索每个参数,检查它是否有效,并将其写入您的输出流。

    这里的一个小挑战是&Data_Struct::parameter1 的类型可能与&Data_Struct::parameter2 不同;所以你的表必须通过包装器、指向基类的指针或类似的东西来保存它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多