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:
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:
final load_from_file(file)

Read from file to deserialize the raw CBOR packet.

Roughly equivalent to:

def load_from_file(self, file):
    return cbor2.load(file)
Parameters:

file (IO[bytes]) – The binary file to read from.

Returns:

the deserialized Python object.

Return type:

Any

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.

datetime_as_timestamp: bool = False
timezone: datetime.tzinfo | None = None
value_sharing: bool = False
default: Callable[..., Any] | None = None
canonical: bool = False
date_as_datetime: bool = False
string_referencing: bool = False
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.

object_hook: Callable[[...], Any] | None = None
tag_hook: Callable[[...], Any] | None = None
str_errors: str = 'strict'