keichi / binary-parser

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

Building parsers programmatically (question) #237

Open catie opened 1 year ago

catie commented 1 year ago

I'm new to Node, so please forgive me if I'm missing something obvious here. I'm building a utility to parse binary files based on a Json definition of the file specification, and while I originally implemented it in Java, that solution is clunky and already showing strain so I'm rebuilding in Node.

My Json elements have types that already match your primitives, but I notice the Parser.primitiveN() function is private. It seems a little silly to re-implement mappings that I can see are happening in reverse once I call parse(), but I could do that if needed. I'm also happy to make the changes to expose PrimitiveTypes and primitiveN(), but looking at the git history it seems like they might've been made private for a reason. If someone could shed some light on why and provide guidance on the best path forward it would be greatly appreciated. Thanks!

keichi commented 1 year ago

Sorry for not getting back to you sooner. IIRC primitiveN is private simply because there were no use cases to generate the parser definition itself dynamically. Also we wanted to minimize the API surface.

Feel free to open a PR to make it public!

catie commented 1 year ago

Makes sense! I'll try and find some time to clean up my fork and get it submitted. Thanks @keichi!