asphalt.serialization.serializers.msgpack

class asphalt.serialization.serializers.msgpack.MsgpackSerializer(packer_options=None, unpacker_options=None, custom_type_codec=None)

Bases: CustomizableSerializer

Serializes 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 msgpack library must be installed. A convenient way to do this is to install asphalt-serialization with the msgpack extra:

$ pip install asphalt-serialization[msgpack]

See also

Msgpack web site

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 None to return marshalled objects as-is

deserialize(payload)

Deserialize bytes into a Python object.

Return type:

Any

property mimetype: str

Return the MIME type for this serialization format.

serialize(obj)

Serialize a Python object into bytes.

Return type:

bytes

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 None to 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:

None

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:

None