From 01b3980f47973eda7d89bb4988ae49c2765db6c6 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Wed, 8 Jul 2020 00:20:50 +0200 Subject: [PATCH] Spec out send, recv and encoding_length --- simple_message_channels/smc.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/simple_message_channels/smc.py b/simple_message_channels/smc.py index 3e7b2b1..4f3ac83 100644 --- a/simple_message_channels/smc.py +++ b/simple_message_channels/smc.py @@ -25,14 +25,22 @@ class SimpleMessageChannel: destroyed: bool = False error: Optional[Exception] = None - # TODO(decentral1se): need to lookup type of what is being passed in - # context: ??? - - # TODO(decentral1se): allow to override instead of callback interface!? - # onmissing: ??? - # onmessage: ??? + # TODO(decentral1se): context, onmessage, onmissing async def send(self, channel: int, type: int, message: bytes) -> bytes: + """Produce data that can be sent over the channel.""" + header = channel << 4 or type + length = self.encoding_length(type, message) + pyvarint.encoding_length(header) + # TODO(decentral1se): implement offset in pyvarint encode/decode + + async def recv(self, data: bytes) -> bool: + """Receive data sent over a channel.""" pass - # TODO(decentral1se): spec out the context manager API of recv + def destroy(self) -> None: + """Mark message channel as destroyed.""" + self.destroyed = True + + def encoding_length(self, type:int, message: bytes) -> int: + """TODO""" + pass