Can structs be made using class decorators

i like struct library but it is designed for c objects and it doesn’t use classes.

i wonder if it is possible to make a class and decorate it using @ such that size of it’s attributes is fixed and determined by user unlike normal int or str
without having to convert them to bytes or using struct.pack

i don’t want to fill my code with boilerplate just for this simple feature. maybe if i could determine maximum size for int and str

something like this could be useful

from structclasses import structclass, sized

@structclass
class User:
    name = sized(str, max_size=64)
    age = sized(int, max_size=4)
1 Like

You can take a look at:

1 Like

thanks. this is great. everyone’s free to post their own solution

Take a look at cytpes.Structure for another similar thing.

1 Like

the way it’s initiated looks nothing like dataclasses, which is something i want

1 Like

Maybe someday!

1 Like