import struct import zlib from .basecodec import BaseCodec from ...errors import InvalidChecksumError class FullCodec(BaseCodec): """ Default Telegram codec. Sends 12 additional bytes and needs to calculate the CRC value of the packet itself. """ def __init__(self): self._send_counter = 0 # Important or Telegram won't reply @staticmethod def header_length(): return 8 @staticmethod def tag(): return None def encode_packet(self, data): # https://core.telegram.org/mtproto#tcp-transport # total length, sequence number, packet and checksum (CRC32) length = len(data) + 12 data = struct.pack('