keichi / binary-parser

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

Referencing target buffer in parser #247

Open AnnoyingMoose opened 10 months ago

AnnoyingMoose commented 10 months ago

Hello!

Is it possible to reference the parameter to Parser.parse() in a parser definition? I.e. something like:

const parser = new Parser()
  .choice({
    tag: "$target.length"
    choices: {
      2: /* buffer is two bytes long */,
      4: /* buffer is four bytes long */,
      6: /* buffer is six bytes long */
    }
  });

Thanks in advance.