keichi / binary-parser

A blazing-fast declarative parser builder for binary data
MIT License
857 stars 133 forks source link

Reading array - unknown size in bytes #211

Closed mzk-bydgoszcz closed 1 year ago

mzk-bydgoszcz commented 1 year ago

Hi.

Is this possible to read array if you don't know it size (you only know number of elements) ?

Example

03 03 02 0102 40 01 02 49 04 00 00 00 10 5843765873456837

03 - number of elements 03 02 0102 - element id 03, length 2 bytes, value 0101 40 01 02 - element id 40, length 01 bytes, value: 02 49 04 00 00 00 10 - element id 49, length 4 bytes, value: 00000010 5843765873456837 - other random data

Result:

[ {id: 3, value: '0102'}, {id: 40, value: '02'}, {id: 49, value: '00000010'} ]

best MZK

keichi commented 1 year ago

Yes, you pass the number of elements to the length option for the array parser. Please see the documentation for the array parser: https://github.com/keichi/binary-parser#arrayname-options

keichi commented 1 year ago

I will close this issue for now. Feel free to reopen if you still have questions.