feat: reduce overhead to reset between messages (#245)

This commit is contained in:
J. Nick Koston
2023-09-10 14:49:02 -05:00
committed by GitHub
parent 42bbff5f74
commit da30b04a15

View File

@@ -258,23 +258,17 @@ class Unmarshaller:
self._buf = bytearray() self._buf = bytearray()
else: else:
del self._buf[:to_clear] del self._buf[:to_clear]
self._message = None self._msg_len = 0 # used to check if we have ready the header
self._pos = 0 self._read_complete = False # used to check if we have ready the message
self._body_len = 0
self._serial = 0
self._header_len = 0
self._message_type = 0
self._flag = 0
self._msg_len = 0
self._is_native = 0
self._read_complete = False
# No need to reset the unpack functions, they are set in _read_header # No need to reset the unpack functions, they are set in _read_header
# every time a new message is processed. # every time a new message is processed.
@property @property
def message(self) -> Optional[Message]: def message(self) -> Optional[Message]:
"""Return the message that has been unmarshalled.""" """Return the message that has been unmarshalled."""
return self._message if self._read_complete:
return self._message
return None
def _has_another_message_in_buffer(self) -> bool: def _has_another_message_in_buffer(self) -> bool:
"""Check if there is another message in the buffer.""" """Check if there is another message in the buffer."""