Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterClientQuotasRequest.borrowed.rs

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