-
Notifications
You must be signed in to change notification settings - Fork 0
Description
These all fall into the same sort of category, but will be needed to handle some more complicated data files. Clumping them all together because most likely implementing for one serializer type will lay the groundwork to easily do it for others.
We need improved versions of various serializers:
- Some sort of "delayed write" / "coupled" type. For example, in Oblivion records, the
sizeattribute shows up 12 bytes before the data it's describing. If we could either mark the size as delayed, and rewind the stream and write it after, allowing the data handler part to update the size, that's be great. Bonus points if the size could optionally be hidden as an attribute somehow.- I'd like this as generic as possible, so
char,unicode, andarraycould grab this size to use / update easily.
- I'd like this as generic as possible, so
- "Unbounded" length
arrays. Basically, unpack until a given number of bytes are unpacked, rather than to a particular number of items. Again, Oblivion motivated. There the subrecords counts aren't recorded. Rather, subrecords just fill up a specified number of bytes.- In general this opens up probably 3 things to potentially specify to the
arraytype:- How the count is determined: static length, unpack a value, read an attribute, or just unpack until a given number of bytes is used.
- Whether the "given number of bytes to unpack" should be verified or not in cases where the count is determined a different way.
- What type of object is stored inside.
- In general this opens up probably 3 things to potentially specify to the
For the "read an attribute" method in array, a more general solution would be optimal, something that char and unicode can use as well. This will probably bleed into union deciders as well, since ATM they only allow some limited serializers as decider results, that can't change on the fly very well. Just spitballing here, but maybe something along the lines of:
get_name_length = attrgetter('name_size')
class MyStruct(Structured):
...
name: Annotated[bytes, char(get_name_length)]Most IDEs/type-checkers / linters throw errors about no expressions in type-hints (makes sense especially with string-ized hints), so this may require pushing more information into Annotated on the user's end. Not ideal. And __class_getitem__ doesn't support keyword only arguments, so dealing with optional arguments there is a pain, especially if we want to support optional ordering, like:
get_length = attrgetter('item_count')
array[Count[get_length], Size[uint32], float32]
array[Count[get_length], float32]
array[float32, Count[get_length], Size[uint32]]
array[float32, Count[get_length], Size[get_size]]
...