I have the following BERTLV:
61394F0BA00000030800001001234579074F05A000012345500E49442D4F6E65205049562042494F5F50107777772E6F626572746875722E636F6D7F66080202800002028000
I'm trying to parse this in a recursive way, so I am treating the first part as a TLV.
Tag: 0x61
, Len: 0x39
, Value: 4F0BA00000030800001001234579074F05A000012345500E49442D4F6E65205049562042494F5F50107777772E6F626572746875722E636F6D
Then I break it down further, and get
Tag: 0x4F
, Len: 0x0B
, Value:
A000000308000010012345
Now, how do I stop? At this point, I know this value is the last leg of this TLV and is not another nested TLV.
Ok after much digging, I found out what the simple
TAG
is actually more than just a number, theTAG
itself actually encoded a brunch of information in there. I order to find out whether theTLV
contains nestedTLV
so that my code would know when to continue processing and when to stop, I had to decode theTAG
.So the
TAG
contains 8 bits, and each one of them have special meaning:The bit that I needed was
B5
in order to determine whether the currentTLV
isConstructed
or not... when isConstructed
it means that currentTLV
consists of multipleTLV
, so for my code, I am using this information to recursively dig in the nestedTLV
.When the
TLV
is notConstructed
that is my stopping case to bubble back up.Here is my recursive function output by parsing the data and checking the bit
B5
inTAG
: