2020-06-22 20:48:09 +02:00
|
|
|
tristanable
|
|
|
|
===========
|
|
|
|
|
2020-06-22 21:36:06 +02:00
|
|
|
Tag-based asynchronous messaging framework
|
|
|
|
|
2020-06-23 09:19:56 +02:00
|
|
|
## Usage
|
|
|
|
|
2020-06-23 09:23:26 +02:00
|
|
|
The entry point is via the `Manager` type, so first create an instance as follows (passing the endpoint `Socket` in as `socket` in this example):
|
2020-06-23 09:19:56 +02:00
|
|
|
|
|
|
|
```d
|
|
|
|
Manager manager = new Manager(socket);
|
|
|
|
```
|
|
|
|
|
2020-06-23 09:23:26 +02:00
|
|
|
Now the event loop would have started, now we are ready to send out some tagged messages and blocking receive for them!
|
|
|
|
|
|
|
|
Let's send out two messages with tags `1` and `2`:
|
|
|
|
|
|
|
|
```d
|
|
|
|
manager.sendMessage(1, [1,2,3,4,5]);
|
|
|
|
manager.sendMessage(2, [6,7,8,9,0]);
|
|
|
|
```
|
|
|
|
|
|
|
|
Now we can start two seperate threads and wait on them both:
|
2020-06-23 09:19:56 +02:00
|
|
|
|
2020-06-23 10:58:11 +02:00
|
|
|
```d
|
|
|
|
byte[] receivedData = manager.receiveMessage(1);
|
|
|
|
```
|
|
|
|
|
|
|
|
```d
|
|
|
|
byte[] receivedData = manager.receiveMessage(2);
|
|
|
|
```
|
|
|
|
|
2020-06-23 09:19:56 +02:00
|
|
|
**TODO**
|
|
|
|
|
2020-06-22 21:36:06 +02:00
|
|
|
## Format
|
|
|
|
|
|
|
|
```
|
2020-06-23 00:33:01 +02:00
|
|
|
[4 bytes (size-2, little endian)][8 bytes - tag][(2-size) bytes - data]
|
2020-06-23 00:33:52 +02:00
|
|
|
```
|
|
|
|
|
2020-06-23 09:18:14 +02:00
|
|
|
## Acknowledgements
|
2020-06-23 00:33:52 +02:00
|
|
|
|
2020-06-23 09:18:14 +02:00
|
|
|
Thansk to Gabby Smuts for the name suggestion 😉️
|