CBOR Serializer

cbor-based network packet serializer module.

The CBOR is an alternative representation of the JSON data models.

See also

Optional Dependencies

Explains how to install cbor extra.

class easynetwork.serializers.cbor.CBORSerializer

Bases: FileBasedPacketSerializer[Any, Any]

A serializer built on top of the cbor2 module.

Needs cbor extra dependencies.

__init__(encoder_config: CBOREncoderConfig | None = None, decoder_config: CBORDecoderConfig | None = None, *, limit: int = DEFAULT_SERIALIZER_LIMIT, debug: bool = False) None
Parameters:
  • encoder_config (CBOREncoderConfig | None) – Parameter object to configure the CBOREncoder.

  • decoder_config (CBORDecoderConfig | None) – Parameter object to configure the CBORDecoder.

  • limit (int) – Maximum buffer size. Used in incremental serialization context.

  • debug (bool) – If True, add information to DeserializeError via the error_info attribute.

final dump_to_file(packet: Any, file: IO[bytes]) None

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: IO[bytes]) Any

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

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
__init__(*, 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) None
class easynetwork.serializers.cbor.CBORDecoderConfig

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'
__init__(*, object_hook: Callable[[...], Any] | None = None, tag_hook: Callable[[...], Any] | None = None, str_errors: str = 'strict') None