1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::convert::From;
use std::sync::mpsc;
use std::sync::mpsc::{Receiver, Sender};
use crate::{Bytes, Event};
use super::{Dispatcher, DispatcherHandle};
pub struct RawDispatcher {
dispatch: u8,
pub rx: Receiver<Event<Bytes>>,
pub tx: Sender<Event<Bytes>>,
handle: Option<DispatcherHandle>,
}
impl RawDispatcher {
pub fn new(dispatch: u8) -> RawDispatcher {
let (transport_tx, rx) = mpsc::channel();
let (tx, transport_rx) = mpsc::channel();
RawDispatcher {
dispatch,
rx,
tx,
handle: Some(DispatcherHandle::new(transport_tx, transport_rx)),
}
}
pub fn rx(&self) -> &Receiver<Event<Bytes>> {
&self.rx
}
pub fn tx(&self) -> &Sender<Event<Bytes>> {
&self.tx
}
}
impl Dispatcher for RawDispatcher {
fn dispatch_byte(&self) -> u8 {
self.dispatch
}
fn get_handle(&mut self) -> DispatcherHandle {
self.handle.take().unwrap()
}
}
pub struct Packet {
pub payload: Vec<u8>,
}
impl From<Vec<u8>> for Packet {
fn from(bytes: Vec<u8>) -> Self {
Packet { payload: bytes }
}
}