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