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