Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
SaslAuthenticateResponse.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        fixed::{get_i16, get_i64, put_i16, put_i64},
9        string_bytes::{
10            bytes_len, compact_bytes_len, compact_nullable_string_len, get_bytes_owned,
11            get_compact_bytes_owned, get_compact_nullable_string_owned, get_nullable_string_owned,
12            nullable_string_len, put_bytes, put_compact_bytes, put_compact_nullable_string,
13            put_nullable_string,
14        },
15    },
16    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 36;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 2;
21pub const FLEXIBLE_MIN: i16 = 2;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25    version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct SaslAuthenticateResponse {
29    pub error_code: i16,
30    pub error_message: Option<String>,
31    pub auth_bytes: ::bytes::Bytes,
32    pub session_lifetime_ms: i64,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl Default for SaslAuthenticateResponse {
36    fn default() -> Self {
37        Self {
38            error_code: 0i16,
39            error_message: Some(String::new()),
40            auth_bytes: bytes::Bytes::new(),
41            session_lifetime_ms: 0i64,
42            unknown_tagged_fields: UnknownTaggedFields::default(),
43        }
44    }
45}
46impl Encode for SaslAuthenticateResponse {
47    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
48        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
49            return Err(ProtocolError::UnsupportedVersion {
50                api_key: API_KEY,
51                version,
52            });
53        }
54        let flex = is_flexible(version);
55        if version >= 0 {
56            put_i16(buf, self.error_code);
57        }
58        if version >= 0 {
59            if flex {
60                let () = put_compact_nullable_string(buf, self.error_message.as_deref());
61            } else {
62                let () = put_nullable_string(buf, self.error_message.as_deref());
63            }
64        }
65        if version >= 0 {
66            if flex {
67                let () = put_compact_bytes(buf, &self.auth_bytes);
68            } else {
69                let () = put_bytes(buf, &self.auth_bytes);
70            }
71        }
72        if version >= 1 {
73            put_i64(buf, self.session_lifetime_ms);
74        }
75        if flex {
76            let tagged = WriteTaggedFields::new();
77            tagged.write(buf, &self.unknown_tagged_fields);
78        }
79        Ok(())
80    }
81    fn encoded_len(&self, version: i16) -> usize {
82        let flex = is_flexible(version);
83        let mut n: usize = 0;
84        if version >= 0 {
85            n += 2;
86        }
87        if version >= 0 {
88            n += if flex {
89                compact_nullable_string_len(self.error_message.as_deref())
90            } else {
91                nullable_string_len(self.error_message.as_deref())
92            };
93        }
94        if version >= 0 {
95            n += if flex {
96                compact_bytes_len(&self.auth_bytes)
97            } else {
98                bytes_len(&self.auth_bytes)
99            };
100        }
101        if version >= 1 {
102            n += 8;
103        }
104        if flex {
105            let known_pairs: Vec<(u32, usize)> = Vec::new();
106            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
107        }
108        n
109    }
110}
111impl Decode<'_> for SaslAuthenticateResponse {
112    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
113        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
114            return Err(ProtocolError::UnsupportedVersion {
115                api_key: API_KEY,
116                version,
117            });
118        }
119        let flex = is_flexible(version);
120        let mut out = Self::default();
121        if version >= 0 {
122            out.error_code = get_i16(buf)?;
123        }
124        if version >= 0 {
125            out.error_message = if flex {
126                get_compact_nullable_string_owned(buf)?
127            } else {
128                get_nullable_string_owned(buf)?
129            };
130        }
131        if version >= 0 {
132            out.auth_bytes = if flex {
133                get_compact_bytes_owned(buf)?
134            } else {
135                get_bytes_owned(buf)?
136            };
137        }
138        if version >= 1 {
139            out.session_lifetime_ms = get_i64(buf)?;
140        }
141        if flex {
142            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
143        }
144        Ok(out)
145    }
146}
147#[cfg(test)]
148impl SaslAuthenticateResponse {
149    #[must_use]
150    pub fn populated(version: i16) -> Self {
151        let mut m = Self::default();
152        if version >= 0 {
153            m.error_code = 1i16;
154        }
155        if version >= 0 {
156            m.error_message = Some("x".to_string());
157        }
158        if version >= 0 {
159            m.auth_bytes = ::bytes::Bytes::from_static(b"x");
160        }
161        if version >= 1 {
162            m.session_lifetime_ms = 1i64;
163        }
164        m
165    }
166}
167/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
168/// Only includes fields valid for the given version.
169#[must_use]
170#[allow(unused_comparisons)]
171pub fn default_json(version: i16) -> ::serde_json::Value {
172    let mut obj = ::serde_json::Map::new();
173    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
174    obj.insert(
175        "errorMessage".to_string(),
176        ::serde_json::Value::String(String::new()),
177    );
178    obj.insert(
179        "authBytes".to_string(),
180        ::serde_json::Value::String(String::new()),
181    );
182    if version >= 1 {
183        obj.insert("sessionLifetimeMs".to_string(), ::serde_json::json!(0));
184    }
185    ::serde_json::Value::Object(obj)
186}