core.custom.custom_msgpack

Attributes

_T

_TypeT

default_serializers

PACK_OPTIONS

Classes

Serializer

Provides a way to encode all objects of a given class or its

BytesSerializer

Serializes objects to a byte string.

StringSerializer

Serializes objects to a string.

DictionarySerializer

Serializes objects that can be built with keyword arguments.

Serializers

Organises the different serializer implementations under a unifiying

Serializable

Classes inheriting from this base are serialised using the

Functions

load_keyed_tuple(...)

make_serializable(→ collections.abc.Callable[[_TypeT], ...)

packb(→ bytes)

unpackb(→ Any)

Module Contents

core.custom.custom_msgpack._T[source]
core.custom.custom_msgpack._TypeT[source]
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.

tag[source]
target[source]
abstractmethod encode(obj: _T) bytes[source]
abstractmethod decode(value: bytes) _T[source]
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.

_encode[source]
_decode[source]
encode(obj: _T) bytes[source]
decode(value: bytes) _T[source]
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.

_encode[source]
_decode[source]
encode(obj: _T) bytes[source]
decode(value: bytes) _T[source]
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

constructor[source]
encode(obj: _T) bytes[source]
decode(value: bytes) _T[source]
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]
encode(value: object) object[source]
decode(tag: int, value: bytes) Any[source]
core.custom.custom_msgpack.default_serializers[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
serialized_keys: ClassVar[collections.abc.Collection[str]][source]
classmethod serializers() Serializers[source]
classmethod __init_subclass__(tag: int, keys: collections.abc.Collection[str], **kwargs: Any)[source]
core.custom.custom_msgpack.make_serializable(*, tag: int, serializers: Serializers = default_serializers) collections.abc.Callable[[_TypeT], _TypeT][source]
core.custom.custom_msgpack.PACK_OPTIONS[source]
core.custom.custom_msgpack.packb(obj: Any) bytes[source]
core.custom.custom_msgpack.unpackb(value: bytes) Any[source]