File: D:/Python311/Lib/site-packages/mysqlx/__pycache__/protocol.cpython-311.pyc
�
�nc՜ � �~ � d Z ddlZddlZddlZddlmZ ddlZdZn
# e $ r dZY nw xY w ddl
ZdZn
# e $ r dZY nw xY wddl
mZmZmZmZ ddlmZmZmZmZmZmZ dd lmZmZ dd
lmZmZmZm Z m!Z! ddl"m#Z# dZ$ ej% d
� � Z& G d� d� � Z' G d� d� � Z( G d� d� � Z) G d� d� � Z*dS )z3Implementation of the X protocol for MySQL servers.� N)�BytesIOTF� )�InterfaceError�NotSupportedError�OperationalError�ProgrammingError)�
ExprParser�build_bool_scalar�
build_expr�build_int_scalar�build_scalar�build_unsigned_int_scalar)�encode_to_bytes�get_item_or_attr)�CRUD_PREPARE_MAPPING�PROTOBUF_REPEATED_TYPES�SERVER_MESSAGES�Message�
mysqlxpb_enum)�Columni� �mysqlxc �$ � e Zd ZdZd� Zd� Zd� ZdS )�
Compressorz�Implements compression/decompression using `zstd_stream`, `lz4_message`
and `deflate_stream` algorithms.
Args:
algorithm (str): Compression algorithm.
.. versionadded:: 8.0.21
c � � || _ |dk r2t j � � | _ t j � � | _ d S |dk r2t
j � � | _ t
j � � | _ d S d | _ d | _ d S )N�zstd_stream�deflate_stream) �
_algorithm�zstd�ZstdCompressor�_compressobj�ZstdDecompressor�_decompressobj�zlib�compressobj�
decompressobj��self� algorithms �1D:\Python311\Lib\site-packages\mysqlx/protocol.py�__init__zCompressor.__init__Z s� � �#����
�%� '� $� 3� 5� 5�D��"&�"7�"9�"9�D����
�*�
*� '� $� 0� 2� 2�D��"&�"4�"6�"6�D���� $�D��"&�D���� c �� � | j dk r| j � |� � S | j dk r{t j � � � 5 }|� � � }||� |� � z
}||� � � z
}ddd� � n# 1 swxY w Y |S | j � |� � }|| j � t j � � z
}|S )z�Compresses data and returns it.
Args:
data (str, bytes or buffer object): Data to be compressed.
Returns:
bytes: Compressed data.
r �lz4_messageN)
r r �compress�lz4�frame�LZ4FrameCompressor�begin�flushr# �Z_SYNC_FLUSH)r'