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