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
use crate::error;
use crate::frame::{Direction, Envelope, Flags, FromCursor, Opcode, Serialize, Version};
use std::io::Cursor;
#[derive(Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash, Copy, Clone)]
pub struct BodyReqOptions;
impl Serialize for BodyReqOptions {
#[inline(always)]
fn serialize(&self, _cursor: &mut Cursor<&mut Vec<u8>>, _version: Version) {}
}
impl FromCursor for BodyReqOptions {
#[inline(always)]
fn from_cursor(_cursor: &mut Cursor<&[u8]>, _version: Version) -> error::Result<Self> {
Ok(BodyReqOptions)
}
}
impl Envelope {
pub fn new_req_options(version: Version) -> Envelope {
let direction = Direction::Request;
let opcode = Opcode::Options;
let body: BodyReqOptions = Default::default();
Envelope::new(
version,
direction,
Flags::empty(),
opcode,
0,
body.serialize_to_vec(version),
None,
vec![],
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_frame_options() {
let frame = Envelope::new_req_options(Version::V4);
assert_eq!(frame.version, Version::V4);
assert_eq!(frame.opcode, Opcode::Options);
assert!(frame.body.is_empty());
}
}