Retriever
Retriever
¶
Used inside a BaseStruct subclass to define its serialization schema from built-in types or other base structs,
allowing setting constraints and hooks
__new__
¶
__new__(data_type: Any, *, min_ver: Version = Version(-1), max_ver: Version = Version(10000), default: Any = None, default_factory: Callable[[Version], Any] | Callable[[Version, Context], Any] = None, repeat: int = 1, remaining_compressed: bool = False, on_read: Callable[[], list[Combinator]] = None, on_write: Callable[[], list[Combinator]] = None) -> Retriever
Create a new retriever property to be used for serialization inside a BaseStruct subclass
Parameters:
-
data_type(Any) –The type of the property used for serialization
-
min_ver(Version, default:Version(-1)) –The minimum struct version which supports this retriever property. If the version of the struct being serialized is less than
min_ver, serialization for this retriever property is skipped. AVersionErrorwill be raised if an attempt to access this property is made in an un-supporting struct. Using SemVer is recommended: https://semver.org/ -
max_ver(Version, default:Version(10000)) –The maximum struct version which supports this retriever property. If the version of the struct being serialized is greater than
max_ver, serialization for this retriever property is skipped. AVersionErrorwill be raised if an attempt to access this property is made in an un-supporting struct. Using SemVer is recommended: https://semver.org/ -
default_factory(Callable[[Version], Any] | Callable[[Version, Context], Any], default:None) –A function that will receive a version when called and must return an instance of data_type
-
repeat(int, default:1) –The number of times this value is repeated. Prefer using fixed length array types over repeats wherever possible. Allowed values for this parameter are:
-2: skip a list, sets the property toNone-1: skip a value, sets the property toNone0: skip a list, set property to []1: serialize a value>1: serialize a list
Note:
-2and-1both skip serialization but-2indicates that the true type of the value of this retriever property is actually alist[data_type](compared to justdata_typewhen it's-1) - this information is needed for type checking if theNonevalue is later set to an actual value -
remaining_compressed(bool, default:False) –If set to
True, the_decompress/_compressmethods from theBaseStructsubclass are used on the remaining bytes before deserialization/serialization of the remaining properties occurs (inclusive) -
on_read(Callable[[], list[Combinator]], default:None) –A function that must return a list of
Combinators to use for fine-grained operations during deserialization -
on_write(Callable[[], list[Combinator]], default:None) –A function that must return a list of
Combinators to use for fine-grained operations during serialization