I say create a TLV class first and available encoding as an enum with a value equal to the linked tag.
Code:
enum encoding { ASCII = 0x01, binary = 0x02};
class TLV
{
unsigned char tag; //a byte
std::vector<unsigned char> value; //a byte array
public:
TLV(unsigned int char, int length, const char* s) {
....
}
};
Then create a parser, lets assume that you have a string literal as an input
Code:
void parser(const char* input, std::vector<TLV>& output) {
...
}
Finally, you just need to encode depending on the tag. You can do so by
Code:
vector<TLV> tlvs = parser("010231310203112233");
for (int i = 0; i < tlvs.size(); ++i) {
if (tlvs[i].tag == ASCII) {
....
} else if (tlvs[i].tag == binary) {
...
}
}
//this could potentially output
//parameter_1 = "11"
//parameter_3 = 0x112233