PMunch / binaryparse

Binary parser for Nim
MIT License
71 stars 6 forks source link

Generate macro #1

Closed alehander92 closed 6 years ago

alehander92 commented 6 years ago

Most of this is a quick macro that suits my needs.

Some notes:

PMunch commented 6 years ago

Hmm, I was hoping the write could use the same format as the read thing I already wrote. And I'm not a fan of having all these exposed procedures helping out. It is however better than having no writer, and the format isn't too dissimilar so I might merge this if I can't come up with something better myself.

alehander92 commented 6 years ago

I wrote it for my goals quickly so I didn't really try to follow the same dsl (but that would be easy to fix) It's one exported function with many overloads (I like this distinction as in many language that would be one function indeed) It's not perfect but it was simple enough for my case: overloading makes the macro a lot simpler

As a whole feel free to reuse anything from this in a more consistent solution

PMunch commented 6 years ago

I've written a writer now. When calling createParser it will create two procedures, one reader and one writer as a tuple. The same format is used for both reader and writer, so you don't have to repeat the format twice for reader and writer. Magic is automatically handled by the writer and any field that is ignored with _ is written as zeroes.