CBOR Serializer
The CBOR is an alternative representation of the JSON
data models.
See also
- Optional Dependencies
Explains how to install required dependencies.
- class easynetwork.serializers.CBORSerializer(encoder_config=None, decoder_config=None, *, debug=False)
Bases:
FileBasedPacketSerializer
[Any
,Any
]A serializer built on top of the
cbor2
module.Needs
cbor
extra dependencies.- Parameters:
encoder_config (CBOREncoderConfig | None) – Parameter object to configure the
CBOREncoder
.decoder_config (CBORDecoderConfig | None) – Parameter object to configure the
CBORDecoder
.debug (bool) – If
True
, add information toDeserializeError
via theerror_info
attribute.
- final dump_to_file(packet, file)
Write the CBOR representation of packet to file.
Roughly equivalent to:
def dump_to_file(self, packet, file): cbor2.dump(packet, file)
- Parameters:
packet (Any) – The Python object to serialize.
file (IO[bytes]) – The binary file to write to.
Configuration
- class easynetwork.serializers.cbor.CBOREncoderConfig(*, datetime_as_timestamp=False, timezone=None, value_sharing=False, default=None, canonical=False, date_as_datetime=False, string_referencing=False)
Bases:
object
A dataclass with the CBOR encoder options.
See
cbor2.CBOREncoder
for details.- timezone: datetime.tzinfo | None = None
- class easynetwork.serializers.cbor.CBORDecoderConfig(*, object_hook=None, tag_hook=None, str_errors='strict')
Bases:
object
A dataclass with the CBOR decoder options.
See
cbor2.CBORDecoder
for details.