I wrote a C + + class that implements most of the BERTLV operations, with the following code:
Https://github.com/vsuu/elib/blob/master/elib2014/BerTLV.h
This implementation uses iterators to unify arrays and streams, so this class can accept array input or stream input.
Examples of operations:
voidTESTBERTLV () {Try{tagtype tag; Char* Tagstr ="\x70\x80"; Char* TAGSTR1 ="\x1f\x70"; BERTLV::P arsetag (tagstr, Tagstr+2, tag); ASSERT (Tag==0x70); BERTLV::P arsetag (TAGSTR1, Tagstr1+2, tag); ASSERT (Tag==0x1f70); uint32_t Len; Char*lenstr ="\x81\x10"; Char*LENSTR2 ="\x79\x10"; Char*LENSTR3 ="\x82\x10\x10"; BERTLV::P Arselen (lenstr, Lenstr+2, Len); ASSERT (Len==0x10); BERTLV::P Arselen (LENSTR2, Lenstr2+2, Len); ASSERT (Len==0x79); BERTLV::P Arselen (LENSTR3, Lenstr3+3, Len); ASSERT (Len==0x1010); BERTLV TLV (0x70); Tlv. SetValue (Hexdata ("5f340101"). ToBin ()); Tlv. AppendChild (BERTLV (0x5A, Hexdata ("123456"). ToBin ())); Tlv. AppendChild (BERTLV (0xbf0c)); Auto PTR= TLV. Findchild (0xbf0c); PTR->appendchild (BERTLV (0x9f4d, Hexdata ("0b0a"). ToBin ())); Tlv. Insertchild (0x9f4d, BERTLV (Hexdata ("95051122334455"). ToBin ())); Bindata Out_buf; BERTLV::ENCAPTLV (TLV, Back_inserter (OUT_BUF)); cout<< Out_buf. Tohex (). C_STR () <<Endl; BERTLV Tlv2; BERTLV::P ARSETLV (Begin (Out_buf), End (OUT_BUF), TLV2); StringStream SS (ios_base::inch| Ios_base:: out|ios_base::binary); SS>>NOSKIPWS; BERTLV::ENCAPTLV (TLV, SS); Tlv2. Clear (); BERTLV::P ARSETLV (SS, Tlv2); Out_buf.clear (); Tlv2. ENCAPTLV (Back_inserter (OUT_BUF)); cout<< Out_buf. Tohex (). C_STR () <<Endl; } Catch(ConstException &e) {cout<<"Error:"<<Endl; cout<< e.what () <<Endl; }}
C + + implementation of BERTLV