Saturday, 15 June 2013

c++ - Encoding a data structure based on TLV encoding -



c++ - Encoding a data structure based on TLV encoding -

i have encode parameters nowadays within info construction based on x.690 encoding. suppose, construction is:

struct data_struct { parameter1 parameter2 parameter3 }

some or of these parameter may having valid data, say, parameter1 , parameter3. supposed encode parameter1 , parameter3 using tlv encoding. have follow sequencial procedure follow this. like,

check whether parameter 1 nowadays if present, find tag of parameter lookup table , encode check whether parameter 2 nowadays if present, find tag of parameter lookup table , encode check whether parameter 3 nowadays if present, find tag of parameter lookup table , encode as procedure repetitive can modularize it? what best way it? is there way access parameters sequentially? how can have relationship between parameter , it's tag?

length of value variable.

you need create table holds pairs of members , tags, {&data_struct::parameter1, tagforparam1}. unavoidable compiler cannot guess tag.

you need define consider "empty" or "valid data". depends on type. e.g. +inf valid float value? so, add together overloaded functions bool isvalid(t)

you can write generic routine walks through table, retrieves each paramter, checks if it's valid, , write output stream.

a slight challenge here type of &data_struct::parameter1 may differ &data_struct::parameter2; table must hold via wrapper, pointer base of operations class, or similar.

c++ encoding tlv

No comments:

Post a Comment