lunixbochs / struc

Better binary packing for Go
MIT License
564 stars 42 forks source link

Added ignore type, for ignoring fields in structs. #62

Closed luckcolors closed 5 years ago

luckcolors commented 5 years ago

Solves #3 . Let me know what you think. šŸ˜„

lunixbochs commented 5 years ago

I think instead of implementing it as a field of size 0, you should just not insert ignored fields into the fields list during parse (in parse.go:parseFieldsLocked, if type is ignore, just skip it).

This will require parseFieldsLocked to use a capacity sized array instead of length, like:

``

And use append instead of fields[i] =

- fields[i] = f
+ fields = append(fields, f)

Iā€™d also prefer to have a test for this, at least with the ignored field by itself, an ignored field before some other fields, at the end of the struct after some other fields, and multiple ignored fields interleaved throughout several fields. struc has pretty high test coverage and Iā€™d like to keep it that way :)

luckcolors commented 5 years ago

Deleted in favor of usage of the already undocumented and implemented "skip" field tag.