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        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, get_compact_nullable_string_owned,
12            get_compact_string_owned, get_nullable_string_owned, get_string_owned,
13            nullable_string_len, put_compact_nullable_string, put_compact_string,
14            put_nullable_string, put_string, string_len,
15        },
16    },
17    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 50;
20pub const MIN_VERSION: i16 = 0;
21pub const MAX_VERSION: i16 = 0;
22pub const FLEXIBLE_MIN: i16 = 0;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26    version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct DescribeUserScramCredentialsResponse {
30    pub throttle_time_ms: i32,
31    pub error_code: i16,
32    pub error_message: Option<String>,
33    pub results: Vec<DescribeUserScramCredentialsResult>,
34    pub unknown_tagged_fields: UnknownTaggedFields,
35}
36impl Default for DescribeUserScramCredentialsResponse {
37    fn default() -> Self {
38        Self {
39            throttle_time_ms: 0i32,
40            error_code: 0i16,
41            error_message: Some(String::new()),
42            results: Vec::new(),
43            unknown_tagged_fields: UnknownTaggedFields::default(),
44        }
45    }
46}
47impl Encode for DescribeUserScramCredentialsResponse {
48    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
49        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
50            return Err(ProtocolError::UnsupportedVersion {
51                api_key: API_KEY,
52                version,
53            });
54        }
55        let flex = is_flexible(version);
56        if version >= 0 {
57            put_i32(buf, self.throttle_time_ms);
58        }
59        if version >= 0 {
60            put_i16(buf, self.error_code);
61        }
62        if version >= 0 {
63            if flex {
64                put_compact_nullable_string(buf, self.error_message.as_deref())?;
65            } else {
66                put_nullable_string(buf, self.error_message.as_deref())?;
67            }
68        }
69        if version >= 0 {
70            {
71                put_array_len(buf, (self.results).len(), flex)?;
72                for it in &self.results {
73                    it.encode(buf, version)?;
74                }
75            }
76        }
77        if flex {
78            let tagged = WriteTaggedFields::new();
79            tagged.write(buf, &self.unknown_tagged_fields)?;
80        }
81        Ok(())
82    }
83    fn encoded_len(&self, version: i16) -> usize {
84        let flex = is_flexible(version);
85        let mut n: usize = 0;
86        if version >= 0 {
87            n += 4;
88        }
89        if version >= 0 {
90            n += 2;
91        }
92        if version >= 0 {
93            n += if flex {
94                compact_nullable_string_len(self.error_message.as_deref())
95            } else {
96                nullable_string_len(self.error_message.as_deref())
97            };
98        }
99        if version >= 0 {
100            n += {
101                let prefix = 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 = 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_owned());
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                put_compact_string(buf, &self.user)?;
200            } else {
201                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                put_compact_nullable_string(buf, self.error_message.as_deref())?;
210            } else {
211                put_nullable_string(buf, self.error_message.as_deref())?;
212            }
213        }
214        if version >= 0 {
215            {
216                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 = array_len_prefix_len((self.credential_infos).len(), flex);
251                let body: usize = (self.credential_infos)
252                    .iter()
253                    .map(|it| it.encoded_len(version))
254                    .sum();
255                prefix + body
256            };
257        }
258        if flex {
259            let known_pairs: Vec<(u32, usize)> = Vec::new();
260            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
261        }
262        n
263    }
264}
265impl Decode<'_> for DescribeUserScramCredentialsResult {
266    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
267        let flex = version >= 0;
268        let mut out = Self::default();
269        if version >= 0 {
270            out.user = if flex {
271                get_compact_string_owned(buf)?
272            } else {
273                get_string_owned(buf)?
274            };
275        }
276        if version >= 0 {
277            out.error_code = get_i16(buf)?;
278        }
279        if version >= 0 {
280            out.error_message = if flex {
281                get_compact_nullable_string_owned(buf)?
282            } else {
283                get_nullable_string_owned(buf)?
284            };
285        }
286        if version >= 0 {
287            out.credential_infos = {
288                let n = get_array_len(buf, flex)?;
289                let mut v = Vec::with_capacity(n);
290                for _ in 0..n {
291                    v.push(CredentialInfo::decode(buf, version)?);
292                }
293                v
294            };
295        }
296        if flex {
297            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
298        }
299        Ok(out)
300    }
301}
302#[cfg(test)]
303impl DescribeUserScramCredentialsResult {
304    #[must_use]
305    pub fn populated(version: i16) -> Self {
306        let mut m = Self::default();
307        if version >= 0 {
308            m.user = "x".to_owned();
309        }
310        if version >= 0 {
311            m.error_code = 1i16;
312        }
313        if version >= 0 {
314            m.error_message = Some("x".to_owned());
315        }
316        if version >= 0 {
317            m.credential_infos = vec![CredentialInfo::populated(version)];
318        }
319        m
320    }
321}
322#[derive(Debug, Clone, PartialEq, Eq, Default)]
323pub struct CredentialInfo {
324    pub mechanism: i8,
325    pub iterations: i32,
326    pub unknown_tagged_fields: UnknownTaggedFields,
327}
328impl Encode for CredentialInfo {
329    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
330        let flex = version >= 0;
331        if version >= 0 {
332            put_i8(buf, self.mechanism);
333        }
334        if version >= 0 {
335            put_i32(buf, self.iterations);
336        }
337        if flex {
338            let tagged = WriteTaggedFields::new();
339            tagged.write(buf, &self.unknown_tagged_fields)?;
340        }
341        Ok(())
342    }
343    fn encoded_len(&self, version: i16) -> usize {
344        let flex = version >= 0;
345        let mut n: usize = 0;
346        if version >= 0 {
347            n += 1;
348        }
349        if version >= 0 {
350            n += 4;
351        }
352        if flex {
353            let known_pairs: Vec<(u32, usize)> = Vec::new();
354            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
355        }
356        n
357    }
358}
359impl Decode<'_> for CredentialInfo {
360    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
361        let flex = version >= 0;
362        let mut out = Self::default();
363        if version >= 0 {
364            out.mechanism = get_i8(buf)?;
365        }
366        if version >= 0 {
367            out.iterations = get_i32(buf)?;
368        }
369        if flex {
370            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
371        }
372        Ok(out)
373    }
374}
375#[cfg(test)]
376impl CredentialInfo {
377    #[must_use]
378    pub fn populated(version: i16) -> Self {
379        let mut m = Self::default();
380        if version >= 0 {
381            m.mechanism = 1i8;
382        }
383        if version >= 0 {
384            m.iterations = 1i32;
385        }
386        m
387    }
388}
389/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
390/// Only includes fields valid for the given version.
391#[must_use]
392#[allow(unused_comparisons)]
393pub fn default_json(_version: i16) -> ::serde_json::Value {
394    let mut obj = ::serde_json::Map::new();
395    obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
396    obj.insert("errorCode".to_owned(), ::serde_json::json!(0));
397    obj.insert(
398        "errorMessage".to_owned(),
399        ::serde_json::Value::String(String::new()),
400    );
401    obj.insert("results".to_owned(), ::serde_json::Value::Array(vec![]));
402    ::serde_json::Value::Object(obj)
403}