jam1garner / binrw

A Rust crate for helping parse and rebuild binary data using ✨macro magic✨.
https://binrw.rs
MIT License
545 stars 35 forks source link

Bit fields #260

Closed joelreymont closed 1 month ago

joelreymont commented 2 months ago

It would be super-helpful to have bit fields like in Deku.

As it stands, I have to create 3 fields to deal with 2 bit fields stored in a 16-bit int:

  1. Two calculated bit fields calculated on read,
  2. A temporary 16-bit field that I read but don't store and that's used to calculated the bit fields,
  3. A bunch of annotations to state what's calculated and skipped on read and write.
v1gnesh commented 2 months ago

Bit fields with both support for both endianness. bilge may fit the bill :)

csnover commented 1 month ago

Thanks for your report! This looks like a duplicate of #192/#222, so I’d recommend to start there. There is also documentation on how to handle bit fields with modular-bitfield. If you are still having trouble, please open a Q&A that shows the format you are parsing so someone can give a more detailed recommendation. Thanks!