Skip to content
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

Optional explicit sizing of structure #22

Open
emesare opened this issue Apr 3, 2023 · 0 comments
Open

Optional explicit sizing of structure #22

emesare opened this issue Apr 3, 2023 · 0 comments

Comments

@emesare
Copy link
Member

emesare commented Apr 3, 2023

class SizedStruct(Structure):
  _size_ = 0x4
  _fields_ = [("len", c_int16)]

_size_ will bound _fields_ & _offsets_ to be at most, >= _size_, while also ensuring that the structures size in memory is respected so that if the fields defined are less than _size_ (in bytes) the subsequent associated reads are starting at _size_. i.e.

class Test(Structure):
  _fields_ = [("sized", SizedStruct), ("num", c_int32)]

The field num should be at offset 0x4 of the structure Test, instead of 0x2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant