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
use rand;
use crate::frame::*;
use crate::types::CBytes;
#[derive(Debug)]
pub struct BodyReqAuthResponse {
data: CBytes,
}
impl BodyReqAuthResponse {
pub fn new(data: CBytes) -> BodyReqAuthResponse {
BodyReqAuthResponse { data: data }
}
}
impl IntoBytes for BodyReqAuthResponse {
fn into_cbytes(&self) -> Vec<u8> {
self.data.into_cbytes()
}
}
impl Frame {
pub fn new_req_auth_response(token_bytes: CBytes) -> Frame {
let version = Version::Request;
let flag = Flag::Ignore;
let stream = rand::random::<u16>();
let opcode = Opcode::AuthResponse;
let body = BodyReqAuthResponse::new(token_bytes);
Frame {
version: version,
flags: vec![flag],
stream: stream,
opcode: opcode,
body: body.into_cbytes(),
tracing_id: None,
warnings: vec![],
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::frame::traits::IntoBytes;
use crate::types::CBytes;
#[test]
fn body_req_auth_response() {
let bytes = CBytes::new(vec![1, 2, 3]);
let body = BodyReqAuthResponse::new(bytes);
assert_eq!(body.into_cbytes(), vec![0, 0, 0, 3, 1, 2, 3]);
}
#[test]
fn frame_body_req_auth_response() {
let bytes = vec![1, 2, 3];
let frame = Frame::new_req_auth_response(CBytes::new(bytes));
assert_eq!(frame.version, Version::Request);
assert_eq!(frame.flags, vec![Flag::Ignore]);
assert_eq!(frame.opcode, Opcode::AuthResponse);
assert_eq!(frame.body, &[0, 0, 0, 3, 1, 2, 3]);
assert_eq!(frame.tracing_id, None);
assert_eq!(frame.warnings.len(), 0);
}
}