kafka_wire_protocol/schema/sasl_authenticate_response/
v0.rs

1// This file was generated. Do not edit.
2
3use std::io::{Read, Result, Write};
4
5use serde::{Deserialize, Serialize};
6#[cfg(test)] use proptest_derive::Arbitrary;
7
8use crate::bytes::{read_bytes, write_bytes};
9use crate::markers::{ApiMessage, Response};
10use crate::readable_writable::{Readable, Writable};
11#[cfg(test)] use crate::test_utils::{proptest_strategies, serde_bytes};
12
13/// SaslAuthenticateResponse, version 0.
14#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
15#[cfg_attr(test, derive(Arbitrary))]
16pub struct SaslAuthenticateResponse {
17    /// The error code, or 0 if there was no error.
18    pub error_code: i16,
19    /// The error message, or null if there was no error.
20    #[cfg_attr(test, proptest(strategy = "proptest_strategies::optional_string()"))]
21    pub error_message: Option<String>,
22    /// The SASL authentication bytes from the server, as defined by the SASL mechanism.
23    #[cfg_attr(test, proptest(strategy = "proptest_strategies::bytes()"))]
24    #[cfg_attr(test, serde(with="serde_bytes"))]
25    pub auth_bytes: Vec<u8>,
26}
27
28impl ApiMessage for SaslAuthenticateResponse {
29    fn api_key(&self) -> i16 {
30        36
31    }
32    
33    fn version(&self) -> i16 {
34        0
35    }
36}
37
38impl Response for SaslAuthenticateResponse { }
39
40impl Default for SaslAuthenticateResponse {
41    fn default() -> Self {
42        SaslAuthenticateResponse {
43            error_code: 0_i16,
44            error_message: Some(String::from("")),
45            auth_bytes: Vec::new(),
46        }
47    }
48}
49
50impl SaslAuthenticateResponse {
51    pub fn new<S1: AsRef<str>>(error_code: i16, error_message: Option<S1>, auth_bytes: Vec<u8>) -> Self {
52        Self {
53            error_code,
54            error_message: error_message.map(|s| s.as_ref().to_string()),
55            auth_bytes,
56        }
57    }
58}
59
60#[cfg(test)]
61mod tests_sasl_authenticate_response_new_and_default {
62    use super::*;
63    
64    #[test]
65    fn test() {
66        let d = SaslAuthenticateResponse::new(
67            0_i16,
68            Some(String::from("")),
69            Vec::new(),
70        );
71        assert_eq!(d, SaslAuthenticateResponse::default());
72    }
73}
74
75impl Readable for SaslAuthenticateResponse {
76    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
77        let error_code = i16::read(input)?;
78        let error_message = Option::<String>::read_ext(input, "error_message", false)?;
79        let auth_bytes = read_bytes(input, "auth_bytes", false)?;
80        Ok(SaslAuthenticateResponse {
81            error_code, error_message, auth_bytes
82        })
83    }
84}
85
86impl Writable for SaslAuthenticateResponse {
87    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
88        self.error_code.write(output)?;
89        self.error_message.write_ext(output, "self.error_message", false)?;
90        write_bytes(output, "self.auth_bytes", &self.auth_bytes, false)?;
91        Ok(())
92    }
93}
94
95#[cfg(test)]
96mod tests {
97    use super::*;
98    use proptest::prelude::*;
99    
100    #[test]
101    fn test_java_default() {
102        crate::test_utils::test_java_default::<SaslAuthenticateResponse>("SaslAuthenticateResponse", 0);
103    }
104    
105    proptest! {
106        #[test]
107        fn test_serde(data: SaslAuthenticateResponse) {
108            crate::test_utils::test_serde(&data)?;
109        }
110    }
111    
112    proptest! {
113        #[test]
114        fn test_java_arbitrary(data: SaslAuthenticateResponse) {
115            crate::test_utils::test_java_arbitrary(&data, "SaslAuthenticateResponse", 0);
116        }
117    }
118}