import struct from zlib import crc32 from .abcs import MissingBytes, OutFn, Transport class Full(Transport): __slots__ = ("_send_seq", "_recv_seq") """ Implementation of the [full transport]: ```text +----+----+----...----+----+ | len| seq| payload | crc| +----+----+----...----+----+ ^^^^ 4 bytes ``` [full transport]: https://core.telegram.org/mtproto/mtproto-transports#full """ def __init__(self) -> None: self._send_seq = 0 self._recv_seq = 0 def pack(self, input: bytes, write: OutFn) -> None: assert len(input) % 4 == 0 length = len(input) + 12 # Unfortunately there's no hasher that can be updated multiple times, # so a temporary buffer must be used to hash it all in one go. tmp = struct.pack(" int: if len(input) < 4: raise MissingBytes(expected=4, got=len(input)) length = struct.unpack_from(" 12, got: {length}") if len(input) < length: raise MissingBytes(expected=length, got=len(input)) seq = struct.unpack_from("