import struct from zlib import crc32 from .connection import Connection, PacketCodec from ...errors import InvalidChecksumError class FullPacketCodec(PacketCodec): tag = None def __init__(self, connection): super().__init__(connection) self._send_counter = 0 # Important or Telegram won't reply 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('