core.custom.custom_msgpack
Attributes
Classes
Provides a way to encode all objects of a given class or its |
|
Serializes objects to a byte string. |
|
Serializes objects to a string. |
|
Serializes objects that can be built with keyword arguments. |
|
Organises the different serializer implementations under a unifiying |
|
Classes inheriting from this base are serialised using the |
Functions
|
|
|
|
|
|
|
Module Contents
- class core.custom.custom_msgpack.Serializer(tag: int, target: type[_T])[source]
Bases:
Generic
[_T
]Provides a way to encode all objects of a given class or its subclasses to and from MessagePack using extension types.
- class core.custom.custom_msgpack.BytesSerializer(tag: int, target: type[_T], encode: collections.abc.Callable[[_T], bytes], decode: collections.abc.Callable[[bytes], _T])[source]
Bases:
Serializer
[_T
]Serializes objects to a byte string.
- class core.custom.custom_msgpack.StringSerializer(tag: int, target: type[_T], encode: collections.abc.Callable[[_T], str], decode: collections.abc.Callable[[str], _T])[source]
Bases:
Serializer
[_T
]Serializes objects to a string.
- class core.custom.custom_msgpack.DictionarySerializer(tag: int, target: type[_T], keys: collections.abc.Iterable[str])[source]
Bases:
Serializer
[_T
]Serializes objects that can be built with keyword arguments.
For example:
class Point: def __init__(self, x, y): self.x = x self.y = y
Can be serialised using:
DictionarySerializer(Point, ('x', 'y'))
Which results in something like this in JSON:
{'x': 1, 'y': 2}
As the internal __dict__ represenation is of no concern, __slots__ may be used:
class Point:
__slots__ = (‘x’, ‘y’)
- def __init__(self, x, y):
self.x = x self.y = y
- class core.custom.custom_msgpack.Serializers[source]
Organises the different serializer implementations under a unifiying interface. This allows the actual encoder/decoder to call a single class without having to worry how the various serializers need to be looked up and called.
- by_tag: dict[int, Serializer[Any]][source]
- by_type: dict[type[object], tuple[int, Serializer[Any]]][source]
- register(serializer: Serializer[Any]) None [source]
- core.custom.custom_msgpack.load_keyed_tuple(b: bytes) sqlalchemy.util._collections.AbstractKeyedTuple[Any] [source]
- class core.custom.custom_msgpack.Serializable[source]
Classes inheriting from this base are serialised using the
DictionarySerializer
class.The keys that should be used need to be specified as follows:
class Point(Serializable, keys=('x', 'y')): def __init__(self, x, y): self.x = x self.y = y
- classmethod serializers() Serializers [source]
- core.custom.custom_msgpack.make_serializable(*, tag: int, serializers: Serializers = default_serializers) collections.abc.Callable[[_TypeT], _TypeT] [source]