Skip to main content

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

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