cassandra_proto/frame/
frame_event.rs1use std::io::Cursor;
2
3use crate::frame::FromCursor;
4use crate::error;
5use crate::frame::events::ServerEvent;
6
7#[derive(Debug)]
8pub struct BodyResEvent {
9 pub event: ServerEvent,
10}
11
12impl FromCursor for BodyResEvent {
13 fn from_cursor(mut cursor: &mut Cursor<&[u8]>) -> error::Result<BodyResEvent> {
14 let event = ServerEvent::from_cursor(&mut cursor)?;
15
16 Ok(BodyResEvent { event: event })
17 }
18}
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23 use std::io::Cursor;
24 use crate::frame::traits::FromCursor;
25 use crate::frame::events::*;
26
27 #[test]
28 fn body_res_event() {
29 let bytes = [0,
31 15,
32 84,
33 79,
34 80,
35 79,
36 76,
37 79,
38 71,
39 89,
40 95,
41 67,
42 72,
43 65,
44 78,
45 71,
46 69,
47 0,
49 8,
50 78,
51 69,
52 87,
53 95,
54 78,
55 79,
56 68,
57 69,
58 0,
60 4,
61 127,
62 0,
63 0,
64 1,
65 0,
66 0,
67 0,
68 1];
69 let mut cursor: Cursor<&[u8]> = Cursor::new(&bytes);
70 let event = BodyResEvent::from_cursor(&mut cursor).unwrap().event;
71
72 match event {
73 ServerEvent::TopologyChange(ref tc) => {
74 assert_eq!(tc.change_type, TopologyChangeType::NewNode);
75 assert_eq!(format!("{:?}", tc.addr.addr), "V4(127.0.0.1:1)");
76 }
77 _ => panic!("should be topology change event"),
78 }
79 }
80}