-
Notifications
You must be signed in to change notification settings - Fork 30
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
having a field with 12 bits #29
Comments
LSB integers with arbitrary bit widths are currently not supported as I haven't really encountered them in my usages. The first thing to precisely define and document would be the per-bit layout for such fields. If you can share your expectations of how this should work based on real-world protocols or devices, that would be of great help. This is properly implemented for MSB integer fields. |
Fair enough. I'm implementing the LIFX binary protocol in rust as a learning exercise for rust (already made this library in python). In this case the 12 bits for the protocol field is just a normal 16 bit field with the last 4 bits stolen by the next three fields. Though I did get a bit further than in my initial example by making the whole struct msb0 and the protocol field look like
Though if I then do something like
I get
Which looks like the bit for the 1024 is in the wrong place. So I did something like
and I get |
I have been arguing about the bit layout of LSB structures, too in #36. In my opinion the bit numbering in lsb0 mode is completely counterintuitive and for example in the example below effectively prevents to specify such a layout. Normally, in little endian architectures/protocols and nobody really cares about lsb0/msb0 bit numbering, always assumes the following one
However, packed_struct marks bits are numbered in a weird order ((endian="lsb" and bit_numbering="lsb0")
The only intuitive mode that kinda matches what we need is A good example is below, it's a real world example from the new bitcoin mining protocol (Stratum V2). It is technically impossible to use packed_struct for this structure in case it will be nested. There is no way to describe an LSB ordering that occupies bits 14:0 for extension field and bit 15 for channel_msg flag. In
@rudib Would the above specification be enough to implement this? |
Also trying to implement the Lifx protocol, did you get any further @delfick ? |
nah, I had better things to work on :) |
Here's an example using c2rust_bitfields if you're interested. |
Hi,
I have a struct that looks like
The problem though is I get this errors
It seems the problem is because the second two bytes are split over 4 fields (12 bits, 1 bit, 1 bit, 2 bits)
is it possible at all to have a PackedStruct with BitsPartialBytes fields ?
Thanks
The text was updated successfully, but these errors were encountered: