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
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::io::Cursor;
use frame::FromCursor;
use error;
use frame::events::ServerEvent;
#[derive(Debug)]
pub struct BodyResEvent {
pub event: ServerEvent,
}
impl FromCursor for BodyResEvent {
fn from_cursor(mut cursor: &mut Cursor<&[u8]>) -> error::Result<BodyResEvent> {
let event = ServerEvent::from_cursor(&mut cursor)?;
Ok(BodyResEvent { event: event })
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::io::Cursor;
use frame::traits::FromCursor;
use frame::events::*;
#[test]
fn body_res_event() {
let bytes = [
0,
15,
84,
79,
80,
79,
76,
79,
71,
89,
95,
67,
72,
65,
78,
71,
69,
0,
8,
78,
69,
87,
95,
78,
79,
68,
69,
0,
4,
127,
0,
0,
1,
0,
0,
0,
1];
let mut cursor: Cursor<&[u8]> = Cursor::new(&bytes);
let event = BodyResEvent::from_cursor(&mut cursor).unwrap().event;
match event {
ServerEvent::TopologyChange(ref tc) => {
assert_eq!(tc.change_type, TopologyChangeType::NewNode);
assert_eq!(format!("{:?}", tc.addr.addr), "V4(127.0.0.1:1)");
}
_ => panic!("should be topology change event"),
}
}
}