Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeClientQuotasResponse.owned.rs

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