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

String with both length and padding #1045

Open
katzuv opened this issue Sep 21, 2023 · 1 comment
Open

String with both length and padding #1045

katzuv opened this issue Sep 21, 2023 · 1 comment
Labels

Comments

@katzuv
Copy link

katzuv commented Sep 21, 2023

Let's say I have this kind of struct: 1 byte of string length, then the ASCII string itself, then padding up to 255 (the padding's length is 255-string length), and then some 3-byte value. So it looks like this:

data = b"\x08mystring\xff\xff\xff\xff\xff\xff\xff ... xab\xcd"

I thought of building this struct with a PaddedString, but another requirement I need is to be able to use .sizeof() on it (for another use in a bigger library I am writing). This is not possible with PaddedString because the size of it can't be determined.

Is there some solution from construct for this? Obviously, I could simply use Byte[255] and slice the string myself, but I was wondering whether construct could do it on its own, while still having a fixed-sized struct.
Thanks!

@arekbulski
Copy link
Member

I would recommend using a custom adapter or parsing class. Simply.

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

No branches or pull requests

2 participants