Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeUserScramCredentialsResponse.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    primitives::{
7        fixed::{get_i8, get_i16, get_i32, put_i8, put_i16, put_i32},
8        string_bytes::{
9            compact_nullable_string_len, compact_string_len, nullable_string_len,
10            put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
11            string_len,
12        },
13        string_bytes_borrowed::{
14            get_compact_nullable_string_borrowed, get_compact_string_borrowed,
15            get_nullable_string_borrowed, get_string_borrowed,
16        },
17    },
18    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 50;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 0;
23pub const FLEXIBLE_MIN: i16 = 0;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27    version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq)]
30pub struct DescribeUserScramCredentialsResponse<'a> {
31    pub throttle_time_ms: i32,
32    pub error_code: i16,
33    pub error_message: Option<&'a str>,
34    pub results: Vec<DescribeUserScramCredentialsResult<'a>>,
35    pub unknown_tagged_fields: UnknownTaggedFields,
36}
37impl Default for DescribeUserScramCredentialsResponse<'_> {
38    fn default() -> Self {
39        Self {
40            throttle_time_ms: 0i32,
41            error_code: 0i16,
42            error_message: Some(""),
43            results: Vec::new(),
44            unknown_tagged_fields: UnknownTaggedFields::default(),
45        }
46    }
47}
48impl DescribeUserScramCredentialsResponse<'_> {
49    /// # Panics
50    ///
51    /// Panics if a records field contains an invalid encoded record batch.
52    #[must_use]
53    pub fn to_owned(
54        &self,
55    ) -> crate::owned::describe_user_scram_credentials_response::DescribeUserScramCredentialsResponse
56    {
57        crate::owned::describe_user_scram_credentials_response::DescribeUserScramCredentialsResponse {
58            throttle_time_ms: (self.throttle_time_ms),
59            error_code: (self.error_code),
60            error_message: (self.error_message).map(std::string::ToString::to_string),
61            results: (self.results).iter().map(DescribeUserScramCredentialsResult::to_owned).collect(),
62            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
63        }
64    }
65}
66impl Encode for DescribeUserScramCredentialsResponse<'_> {
67    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
68        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
69            return Err(ProtocolError::UnsupportedVersion {
70                api_key: API_KEY,
71                version,
72            });
73        }
74        let flex = is_flexible(version);
75        if version >= 0 {
76            put_i32(buf, self.throttle_time_ms);
77        }
78        if version >= 0 {
79            put_i16(buf, self.error_code);
80        }
81        if version >= 0 {
82            if flex {
83                let () = put_compact_nullable_string(buf, self.error_message);
84            } else {
85                let () = put_nullable_string(buf, self.error_message);
86            }
87        }
88        if version >= 0 {
89            {
90                crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
91                for it in &self.results {
92                    it.encode(buf, version)?;
93                }
94            };
95        }
96        if flex {
97            let tagged = WriteTaggedFields::new();
98            tagged.write(buf, &self.unknown_tagged_fields);
99        }
100        Ok(())
101    }
102    fn encoded_len(&self, version: i16) -> usize {
103        let flex = is_flexible(version);
104        let mut n: usize = 0;
105        if version >= 0 {
106            n += 4;
107        }
108        if version >= 0 {
109            n += 2;
110        }
111        if version >= 0 {
112            n += if flex {
113                compact_nullable_string_len(self.error_message)
114            } else {
115                nullable_string_len(self.error_message)
116            };
117        }
118        if version >= 0 {
119            n += {
120                let prefix =
121                    crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
122                let body: usize = (self.results)
123                    .iter()
124                    .map(|it| it.encoded_len(version))
125                    .sum();
126                prefix + body
127            };
128        }
129        if flex {
130            let known_pairs: Vec<(u32, usize)> = Vec::new();
131            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
132        }
133        n
134    }
135}
136impl<'de> DecodeBorrow<'de> for DescribeUserScramCredentialsResponse<'de> {
137    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
138        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
139            return Err(ProtocolError::UnsupportedVersion {
140                api_key: API_KEY,
141                version,
142            });
143        }
144        let flex = is_flexible(version);
145        let mut out = Self::default();
146        if version >= 0 {
147            out.throttle_time_ms = get_i32(buf)?;
148        }
149        if version >= 0 {
150            out.error_code = get_i16(buf)?;
151        }
152        if version >= 0 {
153            out.error_message = if flex {
154                get_compact_nullable_string_borrowed(buf)?
155            } else {
156                get_nullable_string_borrowed(buf)?
157            };
158        }
159        if version >= 0 {
160            out.results = {
161                let n = crate::primitives::array::get_array_len(buf, flex)?;
162                let mut v = Vec::with_capacity(n);
163                for _ in 0..n {
164                    v.push(DescribeUserScramCredentialsResult::decode_borrow(
165                        buf, version,
166                    )?);
167                }
168                v
169            };
170        }
171        if flex {
172            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
173        }
174        Ok(out)
175    }
176}
177#[cfg(test)]
178impl DescribeUserScramCredentialsResponse<'_> {
179    #[must_use]
180    pub fn populated(version: i16) -> Self {
181        let mut m = Self::default();
182        if version >= 0 {
183            m.throttle_time_ms = 1i32;
184        }
185        if version >= 0 {
186            m.error_code = 1i16;
187        }
188        if version >= 0 {
189            m.error_message = Some("x");
190        }
191        if version >= 0 {
192            m.results = vec![DescribeUserScramCredentialsResult::populated(version)];
193        }
194        m
195    }
196}
197#[derive(Debug, Clone, PartialEq, Eq)]
198pub struct DescribeUserScramCredentialsResult<'a> {
199    pub user: &'a str,
200    pub error_code: i16,
201    pub error_message: Option<&'a str>,
202    pub credential_infos: Vec<CredentialInfo>,
203    pub unknown_tagged_fields: UnknownTaggedFields,
204}
205impl Default for DescribeUserScramCredentialsResult<'_> {
206    fn default() -> Self {
207        Self {
208            user: "",
209            error_code: 0i16,
210            error_message: Some(""),
211            credential_infos: Vec::new(),
212            unknown_tagged_fields: UnknownTaggedFields::default(),
213        }
214    }
215}
216impl DescribeUserScramCredentialsResult<'_> {
217    /// # Panics
218    ///
219    /// Panics if a records field contains an invalid encoded record batch.
220    #[must_use]
221    pub fn to_owned(
222        &self,
223    ) -> crate::owned::describe_user_scram_credentials_response::DescribeUserScramCredentialsResult
224    {
225        crate::owned::describe_user_scram_credentials_response::DescribeUserScramCredentialsResult {
226            user: (self.user).to_string(),
227            error_code: (self.error_code),
228            error_message: (self.error_message).map(std::string::ToString::to_string),
229            credential_infos: (self.credential_infos)
230                .iter()
231                .map(CredentialInfo::to_owned)
232                .collect(),
233            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
234        }
235    }
236}
237impl Encode for DescribeUserScramCredentialsResult<'_> {
238    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
239        let flex = version >= 0;
240        if version >= 0 {
241            if flex {
242                let () = put_compact_string(buf, self.user);
243            } else {
244                let () = put_string(buf, self.user);
245            }
246        }
247        if version >= 0 {
248            put_i16(buf, self.error_code);
249        }
250        if version >= 0 {
251            if flex {
252                let () = put_compact_nullable_string(buf, self.error_message);
253            } else {
254                let () = put_nullable_string(buf, self.error_message);
255            }
256        }
257        if version >= 0 {
258            {
259                crate::primitives::array::put_array_len(buf, (self.credential_infos).len(), flex);
260                for it in &self.credential_infos {
261                    it.encode(buf, version)?;
262                }
263            };
264        }
265        if flex {
266            let tagged = WriteTaggedFields::new();
267            tagged.write(buf, &self.unknown_tagged_fields);
268        }
269        Ok(())
270    }
271    fn encoded_len(&self, version: i16) -> usize {
272        let flex = version >= 0;
273        let mut n: usize = 0;
274        if version >= 0 {
275            n += if flex {
276                compact_string_len(self.user)
277            } else {
278                string_len(self.user)
279            };
280        }
281        if version >= 0 {
282            n += 2;
283        }
284        if version >= 0 {
285            n += if flex {
286                compact_nullable_string_len(self.error_message)
287            } else {
288                nullable_string_len(self.error_message)
289            };
290        }
291        if version >= 0 {
292            n += {
293                let prefix = crate::primitives::array::array_len_prefix_len(
294                    (self.credential_infos).len(),
295                    flex,
296                );
297                let body: usize = (self.credential_infos)
298                    .iter()
299                    .map(|it| it.encoded_len(version))
300                    .sum();
301                prefix + body
302            };
303        }
304        if flex {
305            let known_pairs: Vec<(u32, usize)> = Vec::new();
306            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
307        }
308        n
309    }
310}
311impl<'de> DecodeBorrow<'de> for DescribeUserScramCredentialsResult<'de> {
312    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
313        let flex = version >= 0;
314        let mut out = Self::default();
315        if version >= 0 {
316            out.user = if flex {
317                get_compact_string_borrowed(buf)?
318            } else {
319                get_string_borrowed(buf)?
320            };
321        }
322        if version >= 0 {
323            out.error_code = get_i16(buf)?;
324        }
325        if version >= 0 {
326            out.error_message = if flex {
327                get_compact_nullable_string_borrowed(buf)?
328            } else {
329                get_nullable_string_borrowed(buf)?
330            };
331        }
332        if version >= 0 {
333            out.credential_infos = {
334                let n = crate::primitives::array::get_array_len(buf, flex)?;
335                let mut v = Vec::with_capacity(n);
336                for _ in 0..n {
337                    v.push(CredentialInfo::decode_borrow(buf, version)?);
338                }
339                v
340            };
341        }
342        if flex {
343            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
344        }
345        Ok(out)
346    }
347}
348#[cfg(test)]
349impl DescribeUserScramCredentialsResult<'_> {
350    #[must_use]
351    pub fn populated(version: i16) -> Self {
352        let mut m = Self::default();
353        if version >= 0 {
354            m.user = "x";
355        }
356        if version >= 0 {
357            m.error_code = 1i16;
358        }
359        if version >= 0 {
360            m.error_message = Some("x");
361        }
362        if version >= 0 {
363            m.credential_infos = vec![CredentialInfo::populated(version)];
364        }
365        m
366    }
367}
368#[derive(Debug, Clone, PartialEq, Eq, Default)]
369pub struct CredentialInfo {
370    pub mechanism: i8,
371    pub iterations: i32,
372    pub unknown_tagged_fields: UnknownTaggedFields,
373}
374impl CredentialInfo {
375    /// # Panics
376    ///
377    /// Panics if a records field contains an invalid encoded record batch.
378    #[must_use]
379    pub fn to_owned(
380        &self,
381    ) -> crate::owned::describe_user_scram_credentials_response::CredentialInfo {
382        crate::owned::describe_user_scram_credentials_response::CredentialInfo {
383            mechanism: (self.mechanism),
384            iterations: (self.iterations),
385            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
386        }
387    }
388}
389impl Encode for CredentialInfo {
390    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
391        let flex = version >= 0;
392        if version >= 0 {
393            put_i8(buf, self.mechanism);
394        }
395        if version >= 0 {
396            put_i32(buf, self.iterations);
397        }
398        if flex {
399            let tagged = WriteTaggedFields::new();
400            tagged.write(buf, &self.unknown_tagged_fields);
401        }
402        Ok(())
403    }
404    fn encoded_len(&self, version: i16) -> usize {
405        let flex = version >= 0;
406        let mut n: usize = 0;
407        if version >= 0 {
408            n += 1;
409        }
410        if version >= 0 {
411            n += 4;
412        }
413        if flex {
414            let known_pairs: Vec<(u32, usize)> = Vec::new();
415            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
416        }
417        n
418    }
419}
420impl<'de> DecodeBorrow<'de> for CredentialInfo {
421    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
422        let flex = version >= 0;
423        let mut out = Self::default();
424        if version >= 0 {
425            out.mechanism = get_i8(buf)?;
426        }
427        if version >= 0 {
428            out.iterations = get_i32(buf)?;
429        }
430        if flex {
431            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
432        }
433        Ok(out)
434    }
435}
436#[cfg(test)]
437impl CredentialInfo {
438    #[must_use]
439    pub fn populated(version: i16) -> Self {
440        let mut m = Self::default();
441        if version >= 0 {
442            m.mechanism = 1i8;
443        }
444        if version >= 0 {
445            m.iterations = 1i32;
446        }
447        m
448    }
449}