Implement reset method in transport classes and add logging for state resets

This commit is contained in:
Jahongir Qurbonov 2025-06-01 20:17:29 +05:00
parent 602bb6381a
commit 05af28d5e1
No known key found for this signature in database
GPG Key ID: 256976CED13D5F2D
4 changed files with 20 additions and 0 deletions

View File

@ -15,6 +15,10 @@ class Transport(ABC):
def unpack(self, input: bytes | bytearray | memoryview, output: bytearray) -> int:
pass
@abstractmethod
def reset(self):
pass
class MissingBytesError(ValueError):
def __init__(self, *, expected: int, got: int) -> None:

View File

@ -1,3 +1,4 @@
import logging
import struct
from .abcs import BadStatusError, MissingBytesError, OutFn, Transport
@ -60,3 +61,7 @@ class Abridged(Transport):
output += memoryview(input)[header_len : header_len + length]
return header_len + length
def reset(self):
logging.info("Resetting sending of header in abridged transport")
self._init = False

View File

@ -1,3 +1,4 @@
import logging
import struct
from zlib import crc32
@ -61,3 +62,8 @@ class Full(Transport):
self._recv_seq += 1
output += memoryview(input)[8 : length - 4]
return length
def reset(self):
logging.info("Resetting recv and send seqs in full transport")
self._send_seq = 0
self._recv_seq = 0

View File

@ -1,3 +1,4 @@
import logging
import struct
from .abcs import BadStatusError, MissingBytesError, OutFn, Transport
@ -52,3 +53,7 @@ class Intermediate(Transport):
output += memoryview(input)[4 : 4 + length]
return length + 4
def reset(self):
logging.info("Resetting sending of header in intermediate transport")
self._init = False