asphalt.serialization.serializers.msgpack
- class asphalt.serialization.serializers.msgpack.MsgpackSerializer(packer_options=None, unpacker_options=None, custom_type_codec=None)
Bases:
CustomizableSerializerSerializes objects using the msgpack library.
The following defaults are passed to packer/unpacker and can be overridden by setting values for the options explicitly:
use_bin_type=True(packer)raw=False(unpacker)
To use this serializer backend, the
msgpacklibrary must be installed. A convenient way to do this is to installasphalt-serializationwith themsgpackextra:$ pip install asphalt-serialization[msgpack]
See also
- Parameters:
packer_options – keyword arguments passed to
msgpack.packb()unpacker_options – keyword arguments passed to
msgpack.unpackb()custom_type_codec – wrapper to use to wrap custom types after marshalling, or
Noneto return marshalled objects as-is
- class asphalt.serialization.serializers.msgpack.MsgpackTypeCodec(type_code=119, **kwargs)
Bases:
DefaultCustomTypeCodec[MsgpackSerializer]Default custom type codec implementation for
MsgpackSerializer.Wraps marshalled state in either msgpack’s ExtType objects (the default) or dicts (with
type_code=None).- Parameters:
type_code (int | None) – msgpack type code to use, or
Noneto use JSON compatible dict-based wrapping
- register_object_decoder_hook(serializer)
Register a callback on the serializer for unmarshalling previously marshalled objects.
- Parameters:
serializer (
MsgpackSerializer) – the serializer instance to use- Return type:
- register_object_encoder_hook(serializer)
Register a custom encoder callback on the serializer.
This callback would be called when the serializer encounters an object it cannot natively serialize. What the callback returns is specific to each serializer type.
- Parameters:
serializer (
MsgpackSerializer) – the serializer instance to use- Return type: