keichi / binary-parser

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

Maximum call stack size exceeded if parsing a lot of bit fields #233

Open jonathanfady opened 1 year ago

jonathanfady commented 1 year ago

Hi ! I am trying out your package to parse a not so large binary data chunk into a lot of booleans (1200), some integers (50) and some strings (20), and I am getting a Maximum call stack size exceeded when running parse(). My booleans are 1-bit long (bit1) and the rest of the data is split among unit8, int8, uint16, int16, uint32, int32, float and string. If I change the booleans to be parsed as uint8 or something else, the code will run. The whole parsing code is running in a Web Worker but I don't think that changes anything.

The error is generated from the following line, so I guess the TODO makes sense !

private generateBit(ctx: Context) {
    // TODO find better method to handle nested bit fields
    const parser = JSON.parse(JSON.stringify(this));
    parser.options = this.options;

Could you look into this if you ever have the time ? I would love to use your parser to avoid writting the entire parsing code by hand :) If you have any other parser to suggest that manages a lot of bitfields that would also help. Thanks for your great work !