Skip to content
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 flags #319

Open
wezm opened this issue Mar 25, 2022 · 0 comments
Open

Bit flags #319

wezm opened this issue Mar 25, 2022 · 0 comments

Comments

@wezm
Copy link
Contributor

wezm commented Mar 25, 2022

For parsing some formats it's necessary to consult the bits of a value. For example in hvif there are flags in gradients that indicate the size of the colours in the steps of the gradient.

The advanced way to handle this might be with bit-sized types or erlang-style bit patterns.

kaitai has done some interesting prior work on the former: https://doc.kaitai.io/user_guide.html#_bit_sized_integers as has Zig: https://andrewkelley.me/post/a-better-way-to-implement-bit-fields.html

A simpler option could be bitwise primitive ops.

In cases where you just want flag bits you could have bitfield syntax that just desugars into bitwise ops. Something like flags: u8 bits { foo, bar, etc. } where flags.foo is equivalent to flags & mask.

Full disclosure: I copied a bunch of this from chat logs, so credit to the original authors for the content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant