typed_data_converter¶
Converters that pack and unpack serialized data and type information into various combined representation formats.
- class parityos_serialization.utils.typed_data_converter.TypedDataConverter¶
Bases:
Generic[TypedDataT],ABCBase class for converters that inject and extract class information to and from serialized data.
- abstractmethod inject_class_tag(class_tag: str, data: Any) TypedDataT¶
Combine serialized
dataand class informationclass_tagduring serialization.- Parameters:
class_tag – Tag for class that got serialized to
data.data – Serialized data.
- Returns:
Combined representation of class information and serialized data.
- Return type:
typed_data
- abstractmethod extract_class_tag(typed_data: Any) tuple[str, Any]¶
Extract
class_tagand serializeddatafrom combined representation during deserialization.- Parameters:
typed_data – Combined representation of class information and serialized data.
- Returns:
Class tag for target class lookup. data (Any): Serialized data.
- Return type:
class_tag (str)
- class parityos_serialization.utils.typed_data_converter.DictTypedDataConverter¶
Bases:
TypedDataConverter[TypedDataDict]Converts serialized data to and from a
TypedDataDict.- inject_class_tag(class_tag: str, data: Any) TypedDataDict¶
Combine serialized
dataand class informationclass_taginto aTypedDataDict.- Parameters:
class_tag – Tag for class that got serialized to
data.data – Serialized data.
- Returns:
Combined representation of class information and serialized data.
- Return type:
typed_data_dict
- extract_class_tag(typed_data: TypedDataDict) tuple[str, Any]¶
Extract
class_tagand serializeddatafrom aTypedDataDict.- Parameters:
typed_data – Combined representation of class information and serialized data.
- Returns:
Class tag for target class lookup. data (Any): Serialized data.
- Return type:
class_tag (str)
- Raises:
DataError – if
typed_datais not of typeTypedDataDict.
- classmethod is_self_type(obj: object) TypeIs[TypedDataDict]¶
Check whether
objis of the typed data type expected by thisTypedDataConverter.
- class parityos_serialization.utils.typed_data_converter.PairTypedDataConverter¶
Bases:
TypedDataConverter[tuple[str,Any]]Converts serialized data to and from a
TypedDataPair.- inject_class_tag(class_tag: str, data: Any) tuple[str, Any]¶
Combine serialized
dataand class informationclass_taginto aTypedDataPair.- Parameters:
class_tag – Tag for class that got serialized to
data.data – Serialized data.
- Returns:
Combined representation of class information and serialized data.
- Return type:
typed_data_pair
- extract_class_tag(typed_data: tuple[str, Any]) tuple[str, Any]¶
Extract
class_tagand serializeddatafrom aTypedDataPair.- Parameters:
typed_data – Combined representation of class information and serialized data.
- Returns:
Class tag for target class lookup. data (Any): Serialized data.
- Return type:
class_tag (str)
- Raises:
DataError – if
typed_datais not of typeTypedDataPair.