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