Encoding a data structure based on TLV encoding
I have to encode the parameters present inside a structure based on X.690 encoding.
Suppose, my structure is:
Code:
struct Data_Struct
{
parameter1
parameter2
parameter3
}
Some or all of these parameter may be having valid data, say, parameter1 and parameter3.
Then I am supposed to encode only parameter1 and parameter3 using TLV encoding.
Do I have to follow a sequencial procedure to follow this. Like,
Code:
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
As the procedure is repetative can I modularize it? What will be the best way to do it? Is there any way to access the parameters sequentially? How can I have a relationship between the parameter and it's tag? Length of the value is variable.