Closed hecko closed 3 years ago
Hi. Unfortunately pycstruct don't support mix of "bitfields" and "normal" struct members. To be honest I have not seen that mix before and did not even know it was supported by the C standard. It might be something we could add support for but it would take some time and require quite large changes in how pycstruct handles structs/bitfields.
Well this is a no-go for me then :( I'll probably write something myself. The use case is obvious - I have lots of C header files that are used in embedded programming and I need to write lots of Python code without the requirement of manually reflecting changes in C headers into Python dictionaries. I really like your approach though.
Is there an alternative way of bitfield definition that will be correctly parsed by pystruct? Splitting the above example into two structs with the bitfield in a substruct alone?
Hi again. I have now included support for mixed bitfields in structs. Please have a try. Version is 0.6.0.
Note that you might get problems with alignment depending on your struct layout and compiler/architecture. See:
https://pycstruct.readthedocs.io/en/latest/limitations.html
Let me know if it works out for you.
Yup! This works like a charm! Great work!
Its very hard for me to add any details as the code is under NDA, but the bits definition play role somehow (havent found any pattern yet)
Bit fields are defined as such: