Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeUserScramCredentialsResponse.owned.rs

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