Compressor Serializers
Data compressor serializer module.
- class easynetwork.serializers.wrapper.compressor.BZ2CompressorSerializer
Bases:
AbstractCompressorSerializer[_T_SentDTOPacket,_T_ReceivedDTOPacket]A serializer wrapper to handle bzip2 compressed data, built on top of
bz2module.- __init__(serializer: AbstractPacketSerializer[_T_SentDTOPacket, _T_ReceivedDTOPacket], *, compress_level: int | None = None, debug: bool = False) None
- Parameters:
serializer (AbstractPacketSerializer[_T_SentDTOPacket, _T_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[_T_SentDTOPacket,_T_ReceivedDTOPacket]A serializer wrapper to handle zlib compressed data, built on top of
zlibmodule.- __init__(serializer: AbstractPacketSerializer[_T_SentDTOPacket, _T_ReceivedDTOPacket], *, compress_level: int | None = None, debug: bool = False) None
- Parameters:
serializer (AbstractPacketSerializer[_T_SentDTOPacket, _T_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[_T_SentDTOPacket,_T_ReceivedDTOPacket,memoryview]A serializer wrapper base class for compressors.
- __init__(serializer: AbstractPacketSerializer[_T_SentDTOPacket, _T_ReceivedDTOPacket], expected_decompress_error: type[Exception] | tuple[type[Exception], ...], *, debug: bool = False) None
- Parameters:
serializer (AbstractPacketSerializer[_T_SentDTOPacket, _T_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: _T_SentDTOPacket) bytes
Serializes packet and returns the compressed data parts.
See
AbstractPacketSerializer.serialize()documentation for details.- Return type:
- final incremental_serialize(packet: _T_SentDTOPacket) Generator[bytes]
Serializes packet and yields the compressed data parts.
See
AbstractIncrementalPacketSerializer.incremental_serialize()documentation for details.
- final deserialize(data: bytes) _T_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:
_T_ReceivedDTOPacket
- final incremental_deserialize() Generator[None, bytes, tuple[_T_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[_T_ReceivedDTOPacket, TypeAliasForwardRef('bytes | bytearray | memoryview | collections.abc.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:
Generator[None, int, tuple[_T_ReceivedDTOPacket, TypeAliasForwardRef(‘bytes | bytearray | memoryview | collections.abc.Buffer’)]]
- protocol easynetwork.serializers.wrapper.compressor.CompressorInterface
Bases:
ProtocolA compressor object.
Classes that implement this protocol must have the following methods / attributes:
- abstractmethod compress(data: bytes | bytearray | memoryview | collections.abc.Buffer, /) bytes
Provide data to the compressor object.
- Returns:
a chunk of compressed data if possible, or an empty byte string otherwise.
- Return type:
- protocol easynetwork.serializers.wrapper.compressor.DecompressorInterface
Bases:
ProtocolA decompressor object.
Classes that implement this protocol must have the following methods / attributes:
- abstractmethod decompress(data: bytes | bytearray | memoryview | collections.abc.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: