-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Is there a built in way to read/write a vector of bits/bool? #370
Comments
Away from my computer, but this should work: use deku::prelude::*;
#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
struct Bit(#[deku(bits = "1")] u8);
#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
struct Container {
qty: u8,
#[deku(count = "qty")]
bits_data: Vec<Bit>,
}
Interesting idea, I'd support a MR for this. |
Thanks, that works. I also added padding as in the code below to align on bytes boundary. Its also required for
What's still missing is automatic filling of qty on write, so I won't need to fill it in the code.
|
Agreed, this would need to be a breaking change, as |
In the structure I read/write there's a section that represent bits. It begins with a u8 that include the number of bits and then as many u8 as needed (rounded up) that include the bits:
So for example if qty is 12, there are two bytes with the 12 bits of data (and 4 empty).
I am able to read/write it into Vec as shown above but it's inconvenient later to deal with the bits.
I could probably do it with reader/writer, but is there a built in way to do either of the two options I mentioned?
The text was updated successfully, but these errors were encountered: