Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AlterClientQuotasRequest.owned.rs

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