Skip to main content

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