12129
|
1 |
use netbuf;
|
|
2 |
use std::io::Read;
|
|
3 |
use std::io::Result;
|
|
4 |
|
12130
|
5 |
mod messages;
|
|
6 |
mod hwprotocol;
|
12131
|
7 |
mod lexer;
|
12129
|
8 |
|
|
9 |
pub struct FrameDecoder {
|
|
10 |
buf: netbuf::Buf,
|
|
11 |
}
|
|
12 |
|
|
13 |
impl FrameDecoder {
|
|
14 |
pub fn new() -> FrameDecoder {
|
|
15 |
FrameDecoder {
|
|
16 |
buf: netbuf::Buf::new()
|
|
17 |
}
|
|
18 |
}
|
|
19 |
|
|
20 |
pub fn read_from<R: Read>(&mut self, stream: &mut R) -> Result<usize> {
|
|
21 |
self.buf.read_from(stream)
|
|
22 |
}
|
|
23 |
|
|
24 |
pub fn extract_messages(&mut self) -> &[u8] {
|
|
25 |
&self.buf[..]
|
|
26 |
}
|
|
27 |
}
|
12131
|
28 |
|
|
29 |
#[test]
|
|
30 |
fn testparser() {
|
|
31 |
assert_eq!(messages::HWProtocolMessage::Nick("hey".to_string()),
|
|
32 |
hwprotocol::parse_ProtocolMessage("NICK\nhey\n\n").unwrap());
|
|
33 |
}
|