Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeUserScramCredentialsResponse.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_i8, get_i16, get_i32, put_i8, put_i16, put_i32},
9        string_bytes::{
10            compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
11            get_compact_string_owned, get_nullable_string_owned, get_string_owned,
12            nullable_string_len, put_compact_nullable_string, put_compact_string,
13            put_nullable_string, put_string, string_len,
14        },
15    },
16    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 50;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 0;
21pub const FLEXIBLE_MIN: i16 = 0;
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 DescribeUserScramCredentialsResponse {
29    pub throttle_time_ms: i32,
30    pub error_code: i16,
31    pub error_message: Option<String>,
32    pub results: Vec<DescribeUserScramCredentialsResult>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl Default for DescribeUserScramCredentialsResponse {
36    fn default() -> Self {
37        Self {
38            throttle_time_ms: 0i32,
39            error_code: 0i16,
40            error_message: Some(String::new()),
41            results: Vec::new(),
42            unknown_tagged_fields: UnknownTaggedFields::default(),
43        }
44    }
45}
46impl Encode for DescribeUserScramCredentialsResponse {
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_i32(buf, self.throttle_time_ms);
57        }
58        if version >= 0 {
59            put_i16(buf, self.error_code);
60        }
61        if version >= 0 {
62            if flex {
63                let () = put_compact_nullable_string(buf, self.error_message.as_deref());
64            } else {
65                let () = put_nullable_string(buf, self.error_message.as_deref());
66            }
67        }
68        if version >= 0 {
69            {
70                crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
71                for it in &self.results {
72                    it.encode(buf, version)?;
73                }
74            };
75        }
76        if flex {
77            let tagged = WriteTaggedFields::new();
78            tagged.write(buf, &self.unknown_tagged_fields);
79        }
80        Ok(())
81    }
82    fn encoded_len(&self, version: i16) -> usize {
83        let flex = is_flexible(version);
84        let mut n: usize = 0;
85        if version >= 0 {
86            n += 4;
87        }
88        if version >= 0 {
89            n += 2;
90        }
91        if version >= 0 {
92            n += if flex {
93                compact_nullable_string_len(self.error_message.as_deref())
94            } else {
95                nullable_string_len(self.error_message.as_deref())
96            };
97        }
98        if version >= 0 {
99            n += {
100                let prefix =
101                    crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
102                let body: usize = (self.results)
103                    .iter()
104                    .map(|it| it.encoded_len(version))
105                    .sum();
106                prefix + body
107            };
108        }
109        if flex {
110            let known_pairs: Vec<(u32, usize)> = Vec::new();
111            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
112        }
113        n
114    }
115}
116impl Decode<'_> for DescribeUserScramCredentialsResponse {
117    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
118        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
119            return Err(ProtocolError::UnsupportedVersion {
120                api_key: API_KEY,
121                version,
122            });
123        }
124        let flex = is_flexible(version);
125        let mut out = Self::default();
126        if version >= 0 {
127            out.throttle_time_ms = get_i32(buf)?;
128        }
129        if version >= 0 {
130            out.error_code = get_i16(buf)?;
131        }
132        if version >= 0 {
133            out.error_message = if flex {
134                get_compact_nullable_string_owned(buf)?
135            } else {
136                get_nullable_string_owned(buf)?
137            };
138        }
139        if version >= 0 {
140            out.results = {
141                let n = crate::primitives::array::get_array_len(buf, flex)?;
142                let mut v = Vec::with_capacity(n);
143                for _ in 0..n {
144                    v.push(DescribeUserScramCredentialsResult::decode(buf, version)?);
145                }
146                v
147            };
148        }
149        if flex {
150            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
151        }
152        Ok(out)
153    }
154}
155#[cfg(test)]
156impl DescribeUserScramCredentialsResponse {
157    #[must_use]
158    pub fn populated(version: i16) -> Self {
159        let mut m = Self::default();
160        if version >= 0 {
161            m.throttle_time_ms = 1i32;
162        }
163        if version >= 0 {
164            m.error_code = 1i16;
165        }
166        if version >= 0 {
167            m.error_message = Some("x".to_string());
168        }
169        if version >= 0 {
170            m.results = vec![DescribeUserScramCredentialsResult::populated(version)];
171        }
172        m
173    }
174}
175#[derive(Debug, Clone, PartialEq, Eq)]
176pub struct DescribeUserScramCredentialsResult {
177    pub user: String,
178    pub error_code: i16,
179    pub error_message: Option<String>,
180    pub credential_infos: Vec<CredentialInfo>,
181    pub unknown_tagged_fields: UnknownTaggedFields,
182}
183impl Default for DescribeUserScramCredentialsResult {
184    fn default() -> Self {
185        Self {
186            user: String::new(),
187            error_code: 0i16,
188            error_message: Some(String::new()),
189            credential_infos: Vec::new(),
190            unknown_tagged_fields: UnknownTaggedFields::default(),
191        }
192    }
193}
194impl Encode for DescribeUserScramCredentialsResult {
195    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
196        let flex = version >= 0;
197        if version >= 0 {
198            if flex {
199                let () = put_compact_string(buf, &self.user);
200            } else {
201                let () = put_string(buf, &self.user);
202            }
203        }
204        if version >= 0 {
205            put_i16(buf, self.error_code);
206        }
207        if version >= 0 {
208            if flex {
209                let () = put_compact_nullable_string(buf, self.error_message.as_deref());
210            } else {
211                let () = put_nullable_string(buf, self.error_message.as_deref());
212            }
213        }
214        if version >= 0 {
215            {
216                crate::primitives::array::put_array_len(buf, (self.credential_infos).len(), flex);
217                for it in &self.credential_infos {
218                    it.encode(buf, version)?;
219                }
220            };
221        }
222        if flex {
223            let tagged = WriteTaggedFields::new();
224            tagged.write(buf, &self.unknown_tagged_fields);
225        }
226        Ok(())
227    }
228    fn encoded_len(&self, version: i16) -> usize {
229        let flex = version >= 0;
230        let mut n: usize = 0;
231        if version >= 0 {
232            n += if flex {
233                compact_string_len(&self.user)
234            } else {
235                string_len(&self.user)
236            };
237        }
238        if version >= 0 {
239            n += 2;
240        }
241        if version >= 0 {
242            n += if flex {
243                compact_nullable_string_len(self.error_message.as_deref())
244            } else {
245                nullable_string_len(self.error_message.as_deref())
246            };
247        }
248        if version >= 0 {
249            n += {
250                let prefix = crate::primitives::array::array_len_prefix_len(
251                    (self.credential_infos).len(),
252                    flex,
253                );
254                let body: usize = (self.credential_infos)
255                    .iter()
256                    .map(|it| it.encoded_len(version))
257                    .sum();
258                prefix + body
259            };
260        }
261        if flex {
262            let known_pairs: Vec<(u32, usize)> = Vec::new();
263            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
264        }
265        n
266    }
267}
268impl Decode<'_> for DescribeUserScramCredentialsResult {
269    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
270        let flex = version >= 0;
271        let mut out = Self::default();
272        if version >= 0 {
273            out.user = if flex {
274                get_compact_string_owned(buf)?
275            } else {
276                get_string_owned(buf)?
277            };
278        }
279        if version >= 0 {
280            out.error_code = get_i16(buf)?;
281        }
282        if version >= 0 {
283            out.error_message = if flex {
284                get_compact_nullable_string_owned(buf)?
285            } else {
286                get_nullable_string_owned(buf)?
287            };
288        }
289        if version >= 0 {
290            out.credential_infos = {
291                let n = crate::primitives::array::get_array_len(buf, flex)?;
292                let mut v = Vec::with_capacity(n);
293                for _ in 0..n {
294                    v.push(CredentialInfo::decode(buf, version)?);
295                }
296                v
297            };
298        }
299        if flex {
300            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
301        }
302        Ok(out)
303    }
304}
305#[cfg(test)]
306impl DescribeUserScramCredentialsResult {
307    #[must_use]
308    pub fn populated(version: i16) -> Self {
309        let mut m = Self::default();
310        if version >= 0 {
311            m.user = "x".to_string();
312        }
313        if version >= 0 {
314            m.error_code = 1i16;
315        }
316        if version >= 0 {
317            m.error_message = Some("x".to_string());
318        }
319        if version >= 0 {
320            m.credential_infos = vec![CredentialInfo::populated(version)];
321        }
322        m
323    }
324}
325#[derive(Debug, Clone, PartialEq, Eq, Default)]
326pub struct CredentialInfo {
327    pub mechanism: i8,
328    pub iterations: i32,
329    pub unknown_tagged_fields: UnknownTaggedFields,
330}
331impl Encode for CredentialInfo {
332    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
333        let flex = version >= 0;
334        if version >= 0 {
335            put_i8(buf, self.mechanism);
336        }
337        if version >= 0 {
338            put_i32(buf, self.iterations);
339        }
340        if flex {
341            let tagged = WriteTaggedFields::new();
342            tagged.write(buf, &self.unknown_tagged_fields);
343        }
344        Ok(())
345    }
346    fn encoded_len(&self, version: i16) -> usize {
347        let flex = version >= 0;
348        let mut n: usize = 0;
349        if version >= 0 {
350            n += 1;
351        }
352        if version >= 0 {
353            n += 4;
354        }
355        if flex {
356            let known_pairs: Vec<(u32, usize)> = Vec::new();
357            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
358        }
359        n
360    }
361}
362impl Decode<'_> for CredentialInfo {
363    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
364        let flex = version >= 0;
365        let mut out = Self::default();
366        if version >= 0 {
367            out.mechanism = get_i8(buf)?;
368        }
369        if version >= 0 {
370            out.iterations = get_i32(buf)?;
371        }
372        if flex {
373            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
374        }
375        Ok(out)
376    }
377}
378#[cfg(test)]
379impl CredentialInfo {
380    #[must_use]
381    pub fn populated(version: i16) -> Self {
382        let mut m = Self::default();
383        if version >= 0 {
384            m.mechanism = 1i8;
385        }
386        if version >= 0 {
387            m.iterations = 1i32;
388        }
389        m
390    }
391}
392/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
393/// Only includes fields valid for the given version.
394#[must_use]
395#[allow(unused_comparisons)]
396pub fn default_json(_version: i16) -> ::serde_json::Value {
397    let mut obj = ::serde_json::Map::new();
398    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
399    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
400    obj.insert(
401        "errorMessage".to_string(),
402        ::serde_json::Value::String(String::new()),
403    );
404    obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
405    ::serde_json::Value::Object(obj)
406}