fathom icon indicating copy to clipboard operation
fathom copied to clipboard

Bit flags

Open wezm opened this issue 2 years ago • 0 comments

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.

wezm avatar Mar 25 '22 06:03 wezm