asphalt.serialization.serializers.cbor
- class asphalt.serialization.serializers.cbor.CBORSerializer(encoder_options=None, decoder_options=None, custom_type_codec=None)
Serializes objects using CBOR (Concise Binary Object Representation).
To use this serializer backend, the
cbor2
library must be installed. A convenient way to do this is to installasphalt-serialization
with thecbor
extra:$ pip install asphalt-serialization[cbor]
See also
- Parameters
encoder_options – keyword arguments passed to
cbor2.dumps()
decoder_options – keyword arguments passed to
cbor2.loads()
custom_type_codec – wrapper to use to wrap custom types after marshalling, or
None
to return marshalled objects as-is
- class asphalt.serialization.serializers.cbor.CBORTypeCodec(type_tag=4554, **kwargs)
Default custom type codec implementation for
CBORSerializer
.Wraps marshalled state in either CBORTag objects (the default) or dicts (with
type_tag=None
).- Parameters
type_tag (int | None) – CBOR tag number to use, or
None
to use JSON compatible dict-based wrapping
Note
Custom wrapping hooks are ignored when CBORTags are used.
- register_object_decoder_hook(serializer)
Register a callback on the serializer for unmarshalling previously marshalled objects.
- Parameters
serializer (
CBORSerializer
) – 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 (
CBORSerializer
) – the serializer instance to use- Return type