cassandra_protocol/frame/
message_auth_success.rs1use super::Serialize;
2use crate::error;
3use crate::frame::{FromCursor, Version};
4use crate::types::CBytes;
5use std::io::Cursor;
6
7#[derive(Debug, PartialEq, Ord, PartialOrd, Eq, Hash, Clone)]
9pub struct BodyReqAuthSuccess {
10 pub data: CBytes,
11}
12
13impl Serialize for BodyReqAuthSuccess {
14 fn serialize(&self, cursor: &mut Cursor<&mut Vec<u8>>, version: Version) {
15 self.data.serialize(cursor, version);
16 }
17}
18
19impl FromCursor for BodyReqAuthSuccess {
20 fn from_cursor(
21 cursor: &mut Cursor<&[u8]>,
22 version: Version,
23 ) -> error::Result<BodyReqAuthSuccess> {
24 CBytes::from_cursor(cursor, version).map(|data| BodyReqAuthSuccess { data })
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31 use crate::frame::traits::FromCursor;
32 use std::io::Cursor;
33
34 #[test]
35 fn body_req_auth_success() {
36 let bytes = &[0, 0, 0, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
37 let expected = BodyReqAuthSuccess {
38 data: CBytes::new(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
39 };
40
41 {
42 let mut cursor: Cursor<&[u8]> = Cursor::new(bytes);
43 let body = BodyReqAuthSuccess::from_cursor(&mut cursor, Version::V4).unwrap();
44 assert_eq!(
45 body.data.into_bytes().unwrap(),
46 vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
47 );
48 }
49
50 {
51 let mut buffer = Vec::new();
52 let mut cursor = Cursor::new(&mut buffer);
53 expected.serialize(&mut cursor, Version::V4);
54 assert_eq!(buffer, bytes);
55 }
56 }
57}