20 def __init__(self) -> None:
21 self.data = bytearray()
25 def remaining(self) -> int:
26 return len(self.data) - self.position
28 def append(self, data: bytes) ->
None:
30 Appends new data to the end of the buffer
35 data which will be appended
38 self.data.extend(data)
42 Reads one byte from the buffer and increments
43 its internal state by 1
47 int -> byte which was read
51 OverflowError -> if there are no more bytes to read
54 if len(self.data) <= self.position:
55 raise OverflowError(
"All data was extracted from buffer")
57 value = self.data[self.position]
62 def getBytes(self, count: int) -> bytes:
64 Reads N number of bytes from the buffer and increments
65 its internal state by N
70 number of bytes to read
74 bytes -> bytes which were read
78 OverflowError -> if count exceeds number of available bytes
81 if len(self.data) < (self.position + count):
82 raise OverflowError(
"Tried to extract more than than what the buffer has")
84 values = self.data[self.position:self.position + count]
85 self.position += count
89 def getRemaining(self) -> bytes:
91 Reads remaining bytes from the buffer
95 bytes -> bytes which were read
98 remaining = len(self.data) - self.position
99 return self.getBytes(remaining)