Spec out first steps, nothing works yet
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Luke Murphy 2020-06-30 15:09:04 +02:00
parent 18fae5a233
commit 1c67ca74e4
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
7 changed files with 40 additions and 3 deletions

5
NOTES.md Normal file
View File

@ -0,0 +1,5 @@
# HOWTO port
- its a sans-io module, no IO included
- its got a callback API recv -> onmessage which Id like to replace
- plan is then maybe to use a async with API for this handling

View File

@ -2,7 +2,7 @@
[![Build Status](https://drone.autonomic.zone/api/badges/hyperpy/simple-message-channels/status.svg)](https://drone.autonomic.zone/hyperpy/simple-message-channels)
## Wire protocol for Hypercore
## Sans I/O wire protocol for Hypercore
```sh
$ pip install simple-message-channels

View File

@ -21,7 +21,7 @@ maintainer_email = hi@decentral1.se
url = https://git.autonomic.zone/hyperpy/simple-message-channels
project_urls =
Source Code = https://git.autonomic.zone/hyperpy/simple-message-channels
description = Low level wire protocol for Hypercore
description = Sans I/O wire protocol for Hypercore
long_description = file: README.md
license = GPLv3
license_file = LICENSE

View File

@ -1,5 +1,7 @@
"""simple-message-channels module."""
from simple_message_channels.smc import SimpleMessageChannel # noqa
try:
import pkg_resources
except ImportError:
@ -7,6 +9,6 @@ except ImportError:
try:
__version__ = pkg_resources.get_distribution('simple-message-channels').version
__version__ = pkg_resources.get_distribution('simple_message_channels').version
except Exception:
__version__ = 'unknown'

View File

@ -0,0 +1,12 @@
"""Sans I/O wire protocol for Hypercore"""
__all__ = ["SimpleMessageChannel"]
class SimpleMessageChannel:
"""A simple message channel."""
async def send(self, channel: int, type: int, message: bytes) -> bytes:
pass
# TODO(decentral1se): spec out the context manager API of recv

8
test/conftest.py Normal file
View File

@ -0,0 +1,8 @@
import pytest
@pytest.fixture
def smc():
from simple_message_channels import SimpleMessageChannel
return SimpleMessageChannel()

10
test/test_smc.py Normal file
View File

@ -0,0 +1,10 @@
async def test_send_recv(smc):
channel, type, message = 0, 0, b"abc"
payload = await smc.send(channel, type, message)
assert isinstance(payload, bytes)
async with smc.recv(payload) as response:
assert response.channel == channel
assert response.type == type
assert response.message == message