Closed m67hoff closed 3 years ago
Hi, please try the following:
var field = new Parser()
.int8("type")
.int32be("field_length")
.choice("data", {
tag: "type",
choices: {
2: Parser.start().buffer("dir", { length: function(vars) { return vars.field_length; } }),
5: Parser.start().buffer("info", { length: function(vars) { return vars.field_length; } })
}
})
Hi, thanks for help - but no, din't work! The buffer is still empty (it runs w/o error):
{ fieldList:
[ { type: 5, field_length: 110, data: { info: <Buffer > } } ] }
The vars parameter works at least for me (e.g. it has access to the parent variables).
This should now be possible with $parent
or $root
introduced by #166.
Hi, I'm experimenting with this binary parser but was not successful. How can I parse "Type - Length - Value" binary input where each value itself is a nested T-L-V list? I was successful parsing the first T-L-V into an array of buffers. But now parsing this would need something like the length of the parent into the choice:
workrs and gives me an array:
but now the value type 5 "this means type is info" is again a nested T-L-V list:
something like:
seems not to work. It seems there is no way to use the "length" for a later parser. But the "manual" explicit states that array + choice would be "good" for TLV parsing. Is there an example for this ? The examples provided did not help.