New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bit field formatter #29
Comments
functoid
pushed a commit
to functoid/binary-parser
that referenced
this issue
Feb 29, 2016
👍 |
Can functoid's patch please be merged with the main repository (and eventually be made available through npm)? Thanks! |
This is a problem for me too. E.g.:
The formatter for |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can't use formatters with bitfields other than the last one in a sequence, since the bitfield reading code generation gets deferred until the last one, but the formatter code is inserted after each field in a sequence. Thus all the other bit field values get overwritten when the actual reading and bit shifting code is executed, because the formatters were called earlier.
EDIT:
It's been almost five years, but I thought I'd add a concrete example. 😄 I'm using
binary-parser@1.6.2
for these.Here's a simple parser that parses uint8 values, and uses formatter for those (although these formatters just return a constant string).
The generated code is fine. First we read the value to the
vars
and then we immediately replace that value with the formatted version.Here's the same thing, except we're parsing bitfields. We're still using formatters.
Now there's a bug in the generated code:
When parsing multiple successive bitfields, the code that populates the varibles is "deferred" to the end. However, the code that calls the formatters is not deferred. Thus the formatters get called too early, when the values don't exist yet.
The "deferring" feature here causes the issue. Or rather the lack of deferring for the formatters. The bitfield parsing code is only generated when there are no more bitfields in the succession. But the code that calls the formatters is generated every time.
The text was updated successfully, but these errors were encountered: