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    owned::describe_user_scram_credentials_response,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_i8, get_i16, get_i32, put_i8, put_i16, put_i32},
10        string_bytes::{
11            compact_nullable_string_len, compact_string_len, nullable_string_len,
12            put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
13            string_len,
14        },
15        string_bytes_borrowed::{
16            get_compact_nullable_string_borrowed, get_compact_string_borrowed,
17            get_nullable_string_borrowed, get_string_borrowed,
18        },
19    },
20    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
21};
22pub const API_KEY: i16 = 50;
23pub const MIN_VERSION: i16 = 0;
24pub const MAX_VERSION: i16 = 0;
25pub const FLEXIBLE_MIN: i16 = 0;
26#[inline]
27#[must_use]
28pub fn is_flexible(version: i16) -> bool {
29    version >= FLEXIBLE_MIN
30}
31#[derive(Debug, Clone, PartialEq, Eq)]
32pub struct DescribeUserScramCredentialsResponse<'a> {
33    pub throttle_time_ms: i32,
34    pub error_code: i16,
35    pub error_message: Option<&'a str>,
36    pub results: Vec<DescribeUserScramCredentialsResult<'a>>,
37    pub unknown_tagged_fields: UnknownTaggedFields,
38}
39impl Default for DescribeUserScramCredentialsResponse<'_> {
40    fn default() -> Self {
41        Self {
42            throttle_time_ms: 0i32,
43            error_code: 0i16,
44            error_message: Some(""),
45            results: Vec::new(),
46            unknown_tagged_fields: UnknownTaggedFields::default(),
47        }
48    }
49}
50impl DescribeUserScramCredentialsResponse<'_> {
51    #[must_use]
52    pub fn to_owned(
53        &self,
54    ) -> describe_user_scram_credentials_response::DescribeUserScramCredentialsResponse {
55        describe_user_scram_credentials_response::DescribeUserScramCredentialsResponse {
56            throttle_time_ms: (self.throttle_time_ms),
57            error_code: (self.error_code),
58            error_message: (self.error_message).map(str::to_owned),
59            results: (self.results)
60                .iter()
61                .map(DescribeUserScramCredentialsResult::to_owned)
62                .collect(),
63            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
64        }
65    }
66}
67impl Encode for DescribeUserScramCredentialsResponse<'_> {
68    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
69        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
70            return Err(ProtocolError::UnsupportedVersion {
71                api_key: API_KEY,
72                version,
73            });
74        }
75        let flex = is_flexible(version);
76        if version >= 0 {
77            put_i32(buf, self.throttle_time_ms);
78        }
79        if version >= 0 {
80            put_i16(buf, self.error_code);
81        }
82        if version >= 0 {
83            if flex {
84                put_compact_nullable_string(buf, self.error_message)?;
85            } else {
86                put_nullable_string(buf, self.error_message)?;
87            }
88        }
89        if version >= 0 {
90            {
91                put_array_len(buf, (self.results).len(), flex)?;
92                for it in &self.results {
93                    it.encode(buf, version)?;
94                }
95            }
96        }
97        if flex {
98            let tagged = WriteTaggedFields::new();
99            tagged.write(buf, &self.unknown_tagged_fields)?;
100        }
101        Ok(())
102    }
103    fn encoded_len(&self, version: i16) -> usize {
104        let flex = is_flexible(version);
105        let mut n: usize = 0;
106        if version >= 0 {
107            n += 4;
108        }
109        if version >= 0 {
110            n += 2;
111        }
112        if version >= 0 {
113            n += if flex {
114                compact_nullable_string_len(self.error_message)
115            } else {
116                nullable_string_len(self.error_message)
117            };
118        }
119        if version >= 0 {
120            n += {
121                let prefix = 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 = 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    #[must_use]
218    pub fn to_owned(
219        &self,
220    ) -> describe_user_scram_credentials_response::DescribeUserScramCredentialsResult {
221        describe_user_scram_credentials_response::DescribeUserScramCredentialsResult {
222            user: (self.user).to_owned(),
223            error_code: (self.error_code),
224            error_message: (self.error_message).map(str::to_owned),
225            credential_infos: (self.credential_infos)
226                .iter()
227                .map(CredentialInfo::to_owned)
228                .collect(),
229            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
230        }
231    }
232}
233impl Encode for DescribeUserScramCredentialsResult<'_> {
234    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
235        let flex = version >= 0;
236        if version >= 0 {
237            if flex {
238                put_compact_string(buf, self.user)?;
239            } else {
240                put_string(buf, self.user)?;
241            }
242        }
243        if version >= 0 {
244            put_i16(buf, self.error_code);
245        }
246        if version >= 0 {
247            if flex {
248                put_compact_nullable_string(buf, self.error_message)?;
249            } else {
250                put_nullable_string(buf, self.error_message)?;
251            }
252        }
253        if version >= 0 {
254            {
255                put_array_len(buf, (self.credential_infos).len(), flex)?;
256                for it in &self.credential_infos {
257                    it.encode(buf, version)?;
258                }
259            }
260        }
261        if flex {
262            let tagged = WriteTaggedFields::new();
263            tagged.write(buf, &self.unknown_tagged_fields)?;
264        }
265        Ok(())
266    }
267    fn encoded_len(&self, version: i16) -> usize {
268        let flex = version >= 0;
269        let mut n: usize = 0;
270        if version >= 0 {
271            n += if flex {
272                compact_string_len(self.user)
273            } else {
274                string_len(self.user)
275            };
276        }
277        if version >= 0 {
278            n += 2;
279        }
280        if version >= 0 {
281            n += if flex {
282                compact_nullable_string_len(self.error_message)
283            } else {
284                nullable_string_len(self.error_message)
285            };
286        }
287        if version >= 0 {
288            n += {
289                let prefix = array_len_prefix_len((self.credential_infos).len(), flex);
290                let body: usize = (self.credential_infos)
291                    .iter()
292                    .map(|it| it.encoded_len(version))
293                    .sum();
294                prefix + body
295            };
296        }
297        if flex {
298            let known_pairs: Vec<(u32, usize)> = Vec::new();
299            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
300        }
301        n
302    }
303}
304impl<'de> DecodeBorrow<'de> for DescribeUserScramCredentialsResult<'de> {
305    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
306        let flex = version >= 0;
307        let mut out = Self::default();
308        if version >= 0 {
309            out.user = if flex {
310                get_compact_string_borrowed(buf)?
311            } else {
312                get_string_borrowed(buf)?
313            };
314        }
315        if version >= 0 {
316            out.error_code = get_i16(buf)?;
317        }
318        if version >= 0 {
319            out.error_message = if flex {
320                get_compact_nullable_string_borrowed(buf)?
321            } else {
322                get_nullable_string_borrowed(buf)?
323            };
324        }
325        if version >= 0 {
326            out.credential_infos = {
327                let n = get_array_len(buf, flex)?;
328                let mut v = Vec::with_capacity(n);
329                for _ in 0..n {
330                    v.push(CredentialInfo::decode_borrow(buf, version)?);
331                }
332                v
333            };
334        }
335        if flex {
336            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
337        }
338        Ok(out)
339    }
340}
341#[cfg(test)]
342impl DescribeUserScramCredentialsResult<'_> {
343    #[must_use]
344    pub fn populated(version: i16) -> Self {
345        let mut m = Self::default();
346        if version >= 0 {
347            m.user = "x";
348        }
349        if version >= 0 {
350            m.error_code = 1i16;
351        }
352        if version >= 0 {
353            m.error_message = Some("x");
354        }
355        if version >= 0 {
356            m.credential_infos = vec![CredentialInfo::populated(version)];
357        }
358        m
359    }
360}
361#[derive(Debug, Clone, PartialEq, Eq, Default)]
362pub struct CredentialInfo {
363    pub mechanism: i8,
364    pub iterations: i32,
365    pub unknown_tagged_fields: UnknownTaggedFields,
366}
367impl CredentialInfo {
368    #[must_use]
369    pub fn to_owned(&self) -> describe_user_scram_credentials_response::CredentialInfo {
370        describe_user_scram_credentials_response::CredentialInfo {
371            mechanism: (self.mechanism),
372            iterations: (self.iterations),
373            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
374        }
375    }
376}
377impl Encode for CredentialInfo {
378    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
379        let flex = version >= 0;
380        if version >= 0 {
381            put_i8(buf, self.mechanism);
382        }
383        if version >= 0 {
384            put_i32(buf, self.iterations);
385        }
386        if flex {
387            let tagged = WriteTaggedFields::new();
388            tagged.write(buf, &self.unknown_tagged_fields)?;
389        }
390        Ok(())
391    }
392    fn encoded_len(&self, version: i16) -> usize {
393        let flex = version >= 0;
394        let mut n: usize = 0;
395        if version >= 0 {
396            n += 1;
397        }
398        if version >= 0 {
399            n += 4;
400        }
401        if flex {
402            let known_pairs: Vec<(u32, usize)> = Vec::new();
403            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
404        }
405        n
406    }
407}
408impl<'de> DecodeBorrow<'de> for CredentialInfo {
409    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
410        let flex = version >= 0;
411        let mut out = Self::default();
412        if version >= 0 {
413            out.mechanism = get_i8(buf)?;
414        }
415        if version >= 0 {
416            out.iterations = get_i32(buf)?;
417        }
418        if flex {
419            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
420        }
421        Ok(out)
422    }
423}
424#[cfg(test)]
425impl CredentialInfo {
426    #[must_use]
427    pub fn populated(version: i16) -> Self {
428        let mut m = Self::default();
429        if version >= 0 {
430            m.mechanism = 1i8;
431        }
432        if version >= 0 {
433            m.iterations = 1i32;
434        }
435        m
436    }
437}