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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -258,23 +258,17 @@ class Unmarshaller:
self._buf = bytearray()
else:
del self._buf[:to_clear]
self._message = None
self._pos = 0
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
self._msg_len = 0 # used to check if we have ready the header
self._read_complete = False # used to check if we have ready the message
# No need to reset the unpack functions, they are set in _read_header
# every time a new message is processed.
@property
def message(self) -> Optional[Message]:
"""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:
"""Check if there is another message in the buffer."""