simple-message-channels/README.md

37 lines
701 B
Markdown
Raw Normal View History

2020-06-29 23:53:17 +00:00
# simple-message-channels
2020-06-29 23:54:30 +00:00
[![Build Status](https://drone.autonomic.zone/api/badges/hyperpy/simple-message-channels/status.svg)](https://drone.autonomic.zone/hyperpy/simple-message-channels)
## Sans I/O wire protocol for Hypercore
2020-06-29 23:53:17 +00:00
2020-07-07 14:05:55 +00:00
## Install
2020-06-29 23:53:17 +00:00
```sh
$ pip install simple-message-channels
```
2020-07-07 14:05:55 +00:00
## Example
```python
2020-08-01 16:53:22 +00:00
from simple_message_channels import SimpleMessageChannel
2020-08-03 20:23:11 +00:00
smc_a = SimpleMessageChannel()
smc_b = SimpleMessageChannel()
2020-08-01 16:53:22 +00:00
2020-08-03 20:23:11 +00:00
payload = smc_b.send(0, 1, b"foo")
2020-08-05 06:00:22 +00:00
print(f"sent: {payload}")
2020-08-01 16:53:22 +00:00
2020-08-03 20:23:11 +00:00
for idx in range(0, len(payload)):
2020-08-05 06:00:22 +00:00
smc_a.recv(payload[idx : idx + 1])
2020-08-03 20:23:11 +00:00
for msg in smc_a.messages:
print(f"received: {msg}")
2020-08-01 16:53:22 +00:00
```
Output:
```sh
2020-08-05 06:00:22 +00:00
sent: b'\x04\x01foo'
received: (0, 1, b'foo')
2020-07-07 14:05:55 +00:00
```