From 0b99db4cf6900e8edd7483ad5188882a917f637d Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Mon, 3 Aug 2020 22:48:42 +0200 Subject: [PATCH] Spoofing out read_varint --- simple_message_channels/smc.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/simple_message_channels/smc.py b/simple_message_channels/smc.py index 2428da5..1063e2b 100644 --- a/simple_message_channels/smc.py +++ b/simple_message_channels/smc.py @@ -64,8 +64,23 @@ class SimpleMessageChannel: def _read_varint(self, data: bytes, offset: int) -> int: """TODO.""" - pass + while offset < len(data): + self.varint += (data[offset] & 127) * self.factor + self.consumed += 1 - def _next_state(self, data: bytes, offset: int) -> None: + if data[offset] < 128: + state = self._next_state(data, offset + 1) + if state: + return offset + return len(data) + + offset += 1 + + if self.consumed >= 8: + raise RuntimeError("Incoming varint is invalid") + + return len(data) + + def _next_state(self, data: bytes, offset: int) -> bool: """TODO.""" pass