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