cassandra_proto/frame/
frame_options.rs

1use rand;
2
3use crate::frame::*;
4
5/// The structure which represents a body of a frame of type `options`.
6#[derive(Debug, Default)]
7pub struct BodyReqOptions;
8
9impl IntoBytes for BodyReqOptions {
10    fn into_cbytes(&self) -> Vec<u8> {
11        vec![]
12    }
13}
14
15// Frame implementation related to BodyReqStartup
16
17impl Frame {
18    /// Creates new frame of type `options`.
19    pub fn new_req_options() -> Frame {
20        let version = Version::Request;
21        let flag = Flag::Ignore;
22        let stream = rand::random::<u16>();
23        let opcode = Opcode::Options;
24        let body: BodyReqOptions = Default::default();
25
26        Frame { version: version,
27                flags: vec![flag],
28                stream: stream,
29                opcode: opcode,
30                body: body.into_cbytes(),
31                // for request frames it's always None
32                tracing_id: None,
33                warnings: vec![], }
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn test_frame_options() {
43        let frame = Frame::new_req_options();
44        assert_eq!(frame.version, Version::Request);
45        assert_eq!(frame.opcode, Opcode::Options);
46        assert_eq!(frame.body, vec![]);
47    }
48}