Compressor Serializers
Data compressor serializer module.
- class easynetwork.serializers.wrapper.compressor.BZ2CompressorSerializer
Bases:
AbstractCompressorSerializer,GenericA serializer wrapper to handle bzip2 compressed data, built on top of
bz2module.- __init__(serializer: AbstractPacketSerializer[SentDTOPacket, ReceivedDTOPacket], *, compress_level: int | None = None, debug: bool = False) None
- Parameters:
serializer (AbstractPacketSerializer[SentDTOPacket, ReceivedDTOPacket]) – The serializer to wrap.
compress_level (int | None) – bzip2 compression level. Defaults to
9.debug (bool) – If
True, add information toDeserializeErrorvia theerror_infoattribute.
- final new_compressor_stream() bz2.BZ2Compressor
See
AbstractCompressorSerializer.new_compressor_stream()documentation for details.- Return type:
- final new_decompressor_stream() bz2.BZ2Decompressor
See
AbstractCompressorSerializer.new_decompressor_stream()documentation for details.- Return type:
- class easynetwork.serializers.wrapper.compressor.ZlibCompressorSerializer
Bases:
AbstractCompressorSerializer,GenericA serializer wrapper to handle zlib compressed data, built on top of
zlibmodule.- __init__(serializer: AbstractPacketSerializer[SentDTOPacket, ReceivedDTOPacket], *, compress_level: int | None = None, debug: bool = False) None
- Parameters:
serializer (AbstractPacketSerializer[SentDTOPacket, ReceivedDTOPacket]) – The serializer to wrap.
compress_level (int | None) – bzip2 compression level. Defaults to
zlib.Z_BEST_COMPRESSION.debug (bool) – If
True, add information toDeserializeErrorvia theerror_infoattribute.
- final new_compressor_stream() zlib.Compress
See
AbstractCompressorSerializer.new_compressor_stream()documentation for details.- Return type:
zlib.Compress
- final new_decompressor_stream() zlib.Decompress
See
AbstractCompressorSerializer.new_decompressor_stream()documentation for details.- Return type:
zlib.Decompress
Abstract Compressor Interface
- class easynetwork.serializers.wrapper.compressor.AbstractCompressorSerializer
Bases:
BufferedIncrementalPacketSerializer[SentDTOPacket,ReceivedDTOPacket,memoryview],GenericA serializer wrapper base class for compressors.
- __init__(serializer: AbstractPacketSerializer[SentDTOPacket, ReceivedDTOPacket], expected_decompress_error: type[Exception] | tuple[type[Exception], ...], *, debug: bool = False) None
- Parameters:
serializer (AbstractPacketSerializer[SentDTOPacket, ReceivedDTOPacket]) – The serializer to wrap.
expected_decompress_error (type[Exception] | tuple[type[Exception], ...]) – Errors that can be raised by
DecompressorInterface.decompress()implementation, which must be considered as deserialization errors.debug (bool) – If
True, add information toDeserializeErrorvia theerror_infoattribute.
- abstractmethod new_compressor_stream() CompressorInterface
- Returns:
an object suitable for data compression.
- Return type:
- abstractmethod new_decompressor_stream() DecompressorInterface
- Returns:
an object suitable for data decompression.
- Return type:
- final serialize(packet: SentDTOPacket) bytes
Serializes packet and returns the compressed data parts.
See
AbstractPacketSerializer.serialize()documentation for details.- Return type:
- final incremental_serialize(packet: SentDTOPacket) Generator[bytes]
Serializes packet and yields the compressed data parts.
See
AbstractIncrementalPacketSerializer.incremental_serialize()documentation for details.- Return type:
Generator[bytes]
- final deserialize(data: bytes) ReceivedDTOPacket
Decompresses data and returns the deserialized packet.
See
AbstractPacketSerializer.deserialize()documentation for details.- Raises:
DeserializeError –
DecompressorInterface.decompress()does not read until EOF (unused trailing data).DeserializeError –
DecompressorInterface.decompress()raised an error that matches expected_decompress_error.Exception – Any other error raised by
DecompressorInterface.decompress()or the underlying serializer.
- Return type:
ReceivedDTOPacket
- final incremental_deserialize() Generator[None, bytes, tuple[ReceivedDTOPacket, bytes]]
Yields until data decompression is finished and deserializes the decompressed data using the underlying serializer.
See
AbstractIncrementalPacketSerializer.incremental_deserialize()documentation for details.- Raises:
IncrementalDeserializeError –
DecompressorInterface.decompress()raised an error that matches expected_decompress_error.Exception – Any other error raised by
DecompressorInterface.decompress()or the underlying serializer.
- Return type:
- final create_deserializer_buffer(sizehint: int) memoryview
See
BufferedIncrementalPacketSerializer.create_deserializer_buffer()documentation for details.- Return type:
- final buffered_incremental_deserialize(buffer: memoryview) Generator[None, int, tuple[ReceivedDTOPacket, Buffer]]
Yields until data decompression is finished and deserializes the decompressed data using the underlying serializer.
See
BufferedIncrementalPacketSerializer.buffered_incremental_deserialize()documentation for details.- Raises:
IncrementalDeserializeError –
DecompressorInterface.decompress()raised an error that matches expected_decompress_error.Exception – Any other error raised by
DecompressorInterface.decompress()or the underlying serializer.
- Return type:
- protocol easynetwork.serializers.wrapper.compressor.CompressorInterface
Bases:
ProtocolA compressor object.
Classes that implement this protocol must have the following methods / attributes:
- protocol easynetwork.serializers.wrapper.compressor.DecompressorInterface
Bases:
ProtocolA decompressor object.
Classes that implement this protocol must have the following methods / attributes:
- abstractmethod decompress(data: Buffer, /) bytes
Decompress data (a bytes-like object).
Some of data may be buffered internally, for use in later calls to
decompress(). The returned data should be concatenated with the output of any previous calls todecompress().- Returns:
uncompressed data as bytes.
- Return type: