Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeClientQuotasResponse.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    primitives::{
7        fixed::{get_f64, get_i16, get_i32, put_f64, put_i16, put_i32},
8        string_bytes::{
9            compact_nullable_string_len, compact_string_len, nullable_string_len,
10            put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
11            string_len,
12        },
13        string_bytes_borrowed::{
14            get_compact_nullable_string_borrowed, get_compact_string_borrowed,
15            get_nullable_string_borrowed, get_string_borrowed,
16        },
17    },
18    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 48;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 1;
23pub const FLEXIBLE_MIN: i16 = 1;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27    version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq)]
30pub struct DescribeClientQuotasResponse<'a> {
31    pub throttle_time_ms: i32,
32    pub error_code: i16,
33    pub error_message: Option<&'a str>,
34    pub entries: Option<Vec<EntryData<'a>>>,
35    pub unknown_tagged_fields: UnknownTaggedFields,
36}
37impl Default for DescribeClientQuotasResponse<'_> {
38    fn default() -> Self {
39        Self {
40            throttle_time_ms: 0i32,
41            error_code: 0i16,
42            error_message: Some(""),
43            entries: Some(Vec::new()),
44            unknown_tagged_fields: UnknownTaggedFields::default(),
45        }
46    }
47}
48impl DescribeClientQuotasResponse<'_> {
49    /// # Panics
50    ///
51    /// Panics if a records field contains an invalid encoded record batch.
52    #[must_use]
53    pub fn to_owned(
54        &self,
55    ) -> crate::owned::describe_client_quotas_response::DescribeClientQuotasResponse {
56        crate::owned::describe_client_quotas_response::DescribeClientQuotasResponse {
57            throttle_time_ms: (self.throttle_time_ms),
58            error_code: (self.error_code),
59            error_message: (self.error_message).map(std::string::ToString::to_string),
60            entries: (self.entries)
61                .as_ref()
62                .map(|v| v.iter().map(EntryData::to_owned).collect()),
63            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
64        }
65    }
66}
67impl Encode for DescribeClientQuotasResponse<'_> {
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                let () = put_compact_nullable_string(buf, self.error_message);
85            } else {
86                let () = put_nullable_string(buf, self.error_message);
87            }
88        }
89        if version >= 0 {
90            {
91                let len = (self.entries).as_ref().map(Vec::len);
92                crate::primitives::array::put_nullable_array_len(buf, len, flex);
93                if let Some(v) = &self.entries {
94                    for it in v {
95                        it.encode(buf, version)?;
96                    }
97                }
98            };
99        }
100        if flex {
101            let tagged = WriteTaggedFields::new();
102            tagged.write(buf, &self.unknown_tagged_fields);
103        }
104        Ok(())
105    }
106    fn encoded_len(&self, version: i16) -> usize {
107        let flex = is_flexible(version);
108        let mut n: usize = 0;
109        if version >= 0 {
110            n += 4;
111        }
112        if version >= 0 {
113            n += 2;
114        }
115        if version >= 0 {
116            n += if flex {
117                compact_nullable_string_len(self.error_message)
118            } else {
119                nullable_string_len(self.error_message)
120            };
121        }
122        if version >= 0 {
123            n += {
124                let opt: Option<&Vec<_>> = (self.entries).as_ref();
125                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
126                    opt.map(std::vec::Vec::len),
127                    flex,
128                );
129                let body: usize =
130                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
131                prefix + body
132            };
133        }
134        if flex {
135            let known_pairs: Vec<(u32, usize)> = Vec::new();
136            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
137        }
138        n
139    }
140}
141impl<'de> DecodeBorrow<'de> for DescribeClientQuotasResponse<'de> {
142    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
143        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
144            return Err(ProtocolError::UnsupportedVersion {
145                api_key: API_KEY,
146                version,
147            });
148        }
149        let flex = is_flexible(version);
150        let mut out = Self::default();
151        if version >= 0 {
152            out.throttle_time_ms = get_i32(buf)?;
153        }
154        if version >= 0 {
155            out.error_code = get_i16(buf)?;
156        }
157        if version >= 0 {
158            out.error_message = if flex {
159                get_compact_nullable_string_borrowed(buf)?
160            } else {
161                get_nullable_string_borrowed(buf)?
162            };
163        }
164        if version >= 0 {
165            out.entries = {
166                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
167                match opt {
168                    None => None,
169                    Some(n) => {
170                        let mut v = Vec::with_capacity(n);
171                        for _ in 0..n {
172                            v.push(EntryData::decode_borrow(buf, version)?);
173                        }
174                        Some(v)
175                    }
176                }
177            };
178        }
179        if flex {
180            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
181        }
182        Ok(out)
183    }
184}
185#[cfg(test)]
186impl DescribeClientQuotasResponse<'_> {
187    #[must_use]
188    pub fn populated(version: i16) -> Self {
189        let mut m = Self::default();
190        if version >= 0 {
191            m.throttle_time_ms = 1i32;
192        }
193        if version >= 0 {
194            m.error_code = 1i16;
195        }
196        if version >= 0 {
197            m.error_message = Some("x");
198        }
199        if version >= 0 {
200            m.entries = Some(vec![EntryData::populated(version)]);
201        }
202        m
203    }
204}
205#[derive(Debug, Clone, PartialEq, Default)]
206pub struct EntryData<'a> {
207    pub entity: Vec<EntityData<'a>>,
208    pub values: Vec<ValueData<'a>>,
209    pub unknown_tagged_fields: UnknownTaggedFields,
210}
211impl EntryData<'_> {
212    /// # Panics
213    ///
214    /// Panics if a records field contains an invalid encoded record batch.
215    #[must_use]
216    pub fn to_owned(&self) -> crate::owned::describe_client_quotas_response::EntryData {
217        crate::owned::describe_client_quotas_response::EntryData {
218            entity: (self.entity).iter().map(EntityData::to_owned).collect(),
219            values: (self.values).iter().map(ValueData::to_owned).collect(),
220            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
221        }
222    }
223}
224impl Encode for EntryData<'_> {
225    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
226        let flex = version >= 1;
227        if version >= 0 {
228            {
229                crate::primitives::array::put_array_len(buf, (self.entity).len(), flex);
230                for it in &self.entity {
231                    it.encode(buf, version)?;
232                }
233            };
234        }
235        if version >= 0 {
236            {
237                crate::primitives::array::put_array_len(buf, (self.values).len(), flex);
238                for it in &self.values {
239                    it.encode(buf, version)?;
240                }
241            };
242        }
243        if flex {
244            let tagged = WriteTaggedFields::new();
245            tagged.write(buf, &self.unknown_tagged_fields);
246        }
247        Ok(())
248    }
249    fn encoded_len(&self, version: i16) -> usize {
250        let flex = version >= 1;
251        let mut n: usize = 0;
252        if version >= 0 {
253            n += {
254                let prefix =
255                    crate::primitives::array::array_len_prefix_len((self.entity).len(), flex);
256                let body: usize = (self.entity).iter().map(|it| it.encoded_len(version)).sum();
257                prefix + body
258            };
259        }
260        if version >= 0 {
261            n += {
262                let prefix =
263                    crate::primitives::array::array_len_prefix_len((self.values).len(), flex);
264                let body: usize = (self.values).iter().map(|it| it.encoded_len(version)).sum();
265                prefix + body
266            };
267        }
268        if flex {
269            let known_pairs: Vec<(u32, usize)> = Vec::new();
270            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
271        }
272        n
273    }
274}
275impl<'de> DecodeBorrow<'de> for EntryData<'de> {
276    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
277        let flex = version >= 1;
278        let mut out = Self::default();
279        if version >= 0 {
280            out.entity = {
281                let n = crate::primitives::array::get_array_len(buf, flex)?;
282                let mut v = Vec::with_capacity(n);
283                for _ in 0..n {
284                    v.push(EntityData::decode_borrow(buf, version)?);
285                }
286                v
287            };
288        }
289        if version >= 0 {
290            out.values = {
291                let n = crate::primitives::array::get_array_len(buf, flex)?;
292                let mut v = Vec::with_capacity(n);
293                for _ in 0..n {
294                    v.push(ValueData::decode_borrow(buf, version)?);
295                }
296                v
297            };
298        }
299        if flex {
300            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
301        }
302        Ok(out)
303    }
304}
305#[cfg(test)]
306impl EntryData<'_> {
307    #[must_use]
308    pub fn populated(version: i16) -> Self {
309        let mut m = Self::default();
310        if version >= 0 {
311            m.entity = vec![EntityData::populated(version)];
312        }
313        if version >= 0 {
314            m.values = vec![ValueData::populated(version)];
315        }
316        m
317    }
318}
319#[derive(Debug, Clone, PartialEq, Eq)]
320pub struct EntityData<'a> {
321    pub entity_type: &'a str,
322    pub entity_name: Option<&'a str>,
323    pub unknown_tagged_fields: UnknownTaggedFields,
324}
325impl Default for EntityData<'_> {
326    fn default() -> Self {
327        Self {
328            entity_type: "",
329            entity_name: Some(""),
330            unknown_tagged_fields: UnknownTaggedFields::default(),
331        }
332    }
333}
334impl EntityData<'_> {
335    /// # Panics
336    ///
337    /// Panics if a records field contains an invalid encoded record batch.
338    #[must_use]
339    pub fn to_owned(&self) -> crate::owned::describe_client_quotas_response::EntityData {
340        crate::owned::describe_client_quotas_response::EntityData {
341            entity_type: (self.entity_type).to_string(),
342            entity_name: (self.entity_name).map(std::string::ToString::to_string),
343            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
344        }
345    }
346}
347impl Encode for EntityData<'_> {
348    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
349        let flex = version >= 1;
350        if version >= 0 {
351            if flex {
352                let () = put_compact_string(buf, self.entity_type);
353            } else {
354                let () = put_string(buf, self.entity_type);
355            }
356        }
357        if version >= 0 {
358            if flex {
359                let () = put_compact_nullable_string(buf, self.entity_name);
360            } else {
361                let () = put_nullable_string(buf, self.entity_name);
362            }
363        }
364        if flex {
365            let tagged = WriteTaggedFields::new();
366            tagged.write(buf, &self.unknown_tagged_fields);
367        }
368        Ok(())
369    }
370    fn encoded_len(&self, version: i16) -> usize {
371        let flex = version >= 1;
372        let mut n: usize = 0;
373        if version >= 0 {
374            n += if flex {
375                compact_string_len(self.entity_type)
376            } else {
377                string_len(self.entity_type)
378            };
379        }
380        if version >= 0 {
381            n += if flex {
382                compact_nullable_string_len(self.entity_name)
383            } else {
384                nullable_string_len(self.entity_name)
385            };
386        }
387        if flex {
388            let known_pairs: Vec<(u32, usize)> = Vec::new();
389            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
390        }
391        n
392    }
393}
394impl<'de> DecodeBorrow<'de> for EntityData<'de> {
395    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
396        let flex = version >= 1;
397        let mut out = Self::default();
398        if version >= 0 {
399            out.entity_type = if flex {
400                get_compact_string_borrowed(buf)?
401            } else {
402                get_string_borrowed(buf)?
403            };
404        }
405        if version >= 0 {
406            out.entity_name = if flex {
407                get_compact_nullable_string_borrowed(buf)?
408            } else {
409                get_nullable_string_borrowed(buf)?
410            };
411        }
412        if flex {
413            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
414        }
415        Ok(out)
416    }
417}
418#[cfg(test)]
419impl EntityData<'_> {
420    #[must_use]
421    pub fn populated(version: i16) -> Self {
422        let mut m = Self::default();
423        if version >= 0 {
424            m.entity_type = "x";
425        }
426        if version >= 0 {
427            m.entity_name = Some("x");
428        }
429        m
430    }
431}
432#[derive(Debug, Clone, PartialEq)]
433pub struct ValueData<'a> {
434    pub key: &'a str,
435    pub value: f64,
436    pub unknown_tagged_fields: UnknownTaggedFields,
437}
438impl Default for ValueData<'_> {
439    fn default() -> Self {
440        Self {
441            key: "",
442            value: 0.0f64,
443            unknown_tagged_fields: UnknownTaggedFields::default(),
444        }
445    }
446}
447impl ValueData<'_> {
448    /// # Panics
449    ///
450    /// Panics if a records field contains an invalid encoded record batch.
451    #[must_use]
452    pub fn to_owned(&self) -> crate::owned::describe_client_quotas_response::ValueData {
453        crate::owned::describe_client_quotas_response::ValueData {
454            key: (self.key).to_string(),
455            value: (self.value),
456            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
457        }
458    }
459}
460impl Encode for ValueData<'_> {
461    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
462        let flex = version >= 1;
463        if version >= 0 {
464            if flex {
465                let () = put_compact_string(buf, self.key);
466            } else {
467                let () = put_string(buf, self.key);
468            }
469        }
470        if version >= 0 {
471            put_f64(buf, self.value);
472        }
473        if flex {
474            let tagged = WriteTaggedFields::new();
475            tagged.write(buf, &self.unknown_tagged_fields);
476        }
477        Ok(())
478    }
479    fn encoded_len(&self, version: i16) -> usize {
480        let flex = version >= 1;
481        let mut n: usize = 0;
482        if version >= 0 {
483            n += if flex {
484                compact_string_len(self.key)
485            } else {
486                string_len(self.key)
487            };
488        }
489        if version >= 0 {
490            n += 8;
491        }
492        if flex {
493            let known_pairs: Vec<(u32, usize)> = Vec::new();
494            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
495        }
496        n
497    }
498}
499impl<'de> DecodeBorrow<'de> for ValueData<'de> {
500    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
501        let flex = version >= 1;
502        let mut out = Self::default();
503        if version >= 0 {
504            out.key = if flex {
505                get_compact_string_borrowed(buf)?
506            } else {
507                get_string_borrowed(buf)?
508            };
509        }
510        if version >= 0 {
511            out.value = get_f64(buf)?;
512        }
513        if flex {
514            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
515        }
516        Ok(out)
517    }
518}
519#[cfg(test)]
520impl ValueData<'_> {
521    #[must_use]
522    pub fn populated(version: i16) -> Self {
523        let mut m = Self::default();
524        if version >= 0 {
525            m.key = "x";
526        }
527        if version >= 0 {
528            m.value = 1.0f64;
529        }
530        m
531    }
532}