U
    ¯ªhÁ  ã                   @   s<   d dl Z ddlmZmZ G dd„ deƒZG dd„ deƒZdS )é    Né   )Ú
ConnectionÚPacketCodecc                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚAbridgedPacketCodecó   ïs   ïïïïc                 C   s<   t |ƒd? }|dk r"t d|¡}ndt |dd¡ }|| S )Né   é   ÚBó   é   Úlittle)ÚlenÚstructÚpackÚintÚto_bytes)ÚselfÚdataÚlength© r   úK/tmp/pip-unpacked-wheel-c81u5j2r/telethon/network/connection/tcpabridged.pyÚencode_packet
   s
    z!AbridgedPacketCodec.encode_packetc                 Ã   sX   t  d| d¡I d H ¡d }|dkrDt  d| d¡I d H d ¡d }| |d> ¡I d H S )	Nz<Br   r   r   z<ir   ó    r   )r   ÚunpackZreadexactly)r   Úreaderr   r   r   r   Úread_packet   s     ÿÿzAbridgedPacketCodec.read_packetN)Ú__name__Ú
__module__Ú__qualname__ÚtagZobfuscate_tagr   r   r   r   r   r   r      s   r   c                   @   s   e Zd ZdZeZdS )ÚConnectionTcpAbridgedz©
    This is the mode with the lowest overhead, as it will
    only require 1 byte if the packet length is less than
    508 bytes (127 << 2, which is very common).
    N)r   r   r   Ú__doc__r   Zpacket_codecr   r   r   r   r       s   r    )r   Ú
connectionr   r   r   r    r   r   r   r   Ú<module>   s   