cassandra_protocol/frame/
message_options.rs

1use crate::error;
2use crate::frame::{Direction, Envelope, Flags, FromCursor, Opcode, Serialize, Version};
3use std::io::Cursor;
4
5/// The structure which represents a body of a envelope of type `options`.
6#[derive(Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash, Copy, Clone)]
7pub struct BodyReqOptions;
8
9impl Serialize for BodyReqOptions {
10    #[inline(always)]
11    fn serialize(&self, _cursor: &mut Cursor<&mut Vec<u8>>, _version: Version) {}
12}
13
14impl FromCursor for BodyReqOptions {
15    #[inline(always)]
16    fn from_cursor(_cursor: &mut Cursor<&[u8]>, _version: Version) -> error::Result<Self> {
17        Ok(BodyReqOptions)
18    }
19}
20
21impl Envelope {
22    /// Creates new envelope of type `options`.
23    pub fn new_req_options(version: Version) -> Envelope {
24        let direction = Direction::Request;
25        let opcode = Opcode::Options;
26        let body: BodyReqOptions = Default::default();
27
28        Envelope::new(
29            version,
30            direction,
31            Flags::empty(),
32            opcode,
33            0,
34            body.serialize_to_vec(version),
35            None,
36            vec![],
37        )
38    }
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_frame_options() {
47        let frame = Envelope::new_req_options(Version::V4);
48        assert_eq!(frame.version, Version::V4);
49        assert_eq!(frame.opcode, Opcode::Options);
50        assert!(frame.body.is_empty());
51    }
52}