Mock out beginnings of the recv logic
This commit is contained in:
parent
af1736748d
commit
388c077534
@ -1,5 +1,5 @@
|
|||||||
"""Sans I/O wire protocol for Hypercore"""
|
"""Sans I/O wire protocol for Hypercore"""
|
||||||
from typing import List, Tuple
|
from typing import List, Optional, Tuple
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
from pyvarint import encode, encoding_length
|
from pyvarint import encode, encoding_length
|
||||||
@ -11,6 +11,15 @@ __all__ = ["SimpleMessageChannel"]
|
|||||||
class SimpleMessageChannel:
|
class SimpleMessageChannel:
|
||||||
"""A simple message channel."""
|
"""A simple message channel."""
|
||||||
|
|
||||||
|
message: Optional[Tuple[int, int, bytes]] = None
|
||||||
|
varint: int = 0
|
||||||
|
factor: int = 1
|
||||||
|
length: int = 0
|
||||||
|
header: int = 0
|
||||||
|
state: int = 0
|
||||||
|
consumed = 0
|
||||||
|
max_size = 8 * 1024 * 1024
|
||||||
|
|
||||||
def send(self, channel: int, type: int, message: bytes) -> bytes:
|
def send(self, channel: int, type: int, message: bytes) -> bytes:
|
||||||
"""Encode a channel, type and message data to be sent.
|
"""Encode a channel, type and message data to be sent.
|
||||||
|
|
||||||
@ -32,9 +41,30 @@ class SimpleMessageChannel:
|
|||||||
payload += self.send(channel, type, message)
|
payload += self.send(channel, type, message)
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
def recv(self, data: bytes) -> Tuple[int, int, bytes]:
|
def recv(self, data: bytes) -> None:
|
||||||
"""Encode a channel, type, message to be sent.
|
"""Encode a channel, type, message to be sent.
|
||||||
|
|
||||||
:param data: the message data
|
:param data: the message data
|
||||||
"""
|
"""
|
||||||
|
offset = 0
|
||||||
|
|
||||||
|
while offset < len(data):
|
||||||
|
if self.state == 2:
|
||||||
|
offset = self._read_msg(data, offset)
|
||||||
|
else:
|
||||||
|
offset = self._read_varint(data, offset)
|
||||||
|
|
||||||
|
if self.state == 2 and self.length == 0:
|
||||||
|
self._read_msg(data, offset)
|
||||||
|
|
||||||
|
def _read_msg(self, data: bytes, offset: int) -> int:
|
||||||
|
"""TODO."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _read_varint(self, data: bytes, offset: int) -> int:
|
||||||
|
"""TODO."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _next_state(self, data: bytes, offset: int) -> None:
|
||||||
|
"""TODO."""
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user