Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterClientQuotasResponse.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_i16, get_i32, 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 = 49;
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, Eq, Default)]
25pub struct AlterClientQuotasResponse {
26    pub throttle_time_ms: i32,
27    pub entries: Vec<EntryData>,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for AlterClientQuotasResponse {
31    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33            return Err(ProtocolError::UnsupportedVersion {
34                api_key: API_KEY,
35                version,
36            });
37        }
38        let flex = is_flexible(version);
39        if version >= 0 {
40            put_i32(buf, self.throttle_time_ms);
41        }
42        if version >= 0 {
43            {
44                crate::primitives::array::put_array_len(buf, (self.entries).len(), flex);
45                for it in &self.entries {
46                    it.encode(buf, version)?;
47                }
48            }
49        }
50        if flex {
51            let tagged = WriteTaggedFields::new();
52            tagged.write(buf, &self.unknown_tagged_fields);
53        }
54        Ok(())
55    }
56    fn encoded_len(&self, version: i16) -> usize {
57        let flex = is_flexible(version);
58        let mut n: usize = 0;
59        if version >= 0 {
60            n += 4;
61        }
62        if version >= 0 {
63            n += {
64                let prefix =
65                    crate::primitives::array::array_len_prefix_len((self.entries).len(), flex);
66                let body: usize = (self.entries)
67                    .iter()
68                    .map(|it| it.encoded_len(version))
69                    .sum();
70                prefix + body
71            };
72        }
73        if flex {
74            let known_pairs: Vec<(u32, usize)> = Vec::new();
75            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
76        }
77        n
78    }
79}
80impl Decode<'_> for AlterClientQuotasResponse {
81    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
82        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83            return Err(ProtocolError::UnsupportedVersion {
84                api_key: API_KEY,
85                version,
86            });
87        }
88        let flex = is_flexible(version);
89        let mut out = Self::default();
90        if version >= 0 {
91            out.throttle_time_ms = get_i32(buf)?;
92        }
93        if version >= 0 {
94            out.entries = {
95                let n = crate::primitives::array::get_array_len(buf, flex)?;
96                let mut v = Vec::with_capacity(n);
97                for _ in 0..n {
98                    v.push(EntryData::decode(buf, version)?);
99                }
100                v
101            };
102        }
103        if flex {
104            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
105        }
106        Ok(out)
107    }
108}
109#[cfg(test)]
110impl AlterClientQuotasResponse {
111    #[must_use]
112    pub fn populated(version: i16) -> Self {
113        let mut m = Self::default();
114        if version >= 0 {
115            m.throttle_time_ms = 1i32;
116        }
117        if version >= 0 {
118            m.entries = vec![EntryData::populated(version)];
119        }
120        m
121    }
122}
123#[derive(Debug, Clone, PartialEq, Eq, Default)]
124pub struct EntryData {
125    pub error_code: i16,
126    pub error_message: Option<String>,
127    pub entity: Vec<EntityData>,
128    pub unknown_tagged_fields: UnknownTaggedFields,
129}
130impl Encode for EntryData {
131    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
132        let flex = version >= 1;
133        if version >= 0 {
134            put_i16(buf, self.error_code);
135        }
136        if version >= 0 {
137            if flex {
138                put_compact_nullable_string(buf, self.error_message.as_deref());
139            } else {
140                put_nullable_string(buf, self.error_message.as_deref());
141            }
142        }
143        if version >= 0 {
144            {
145                crate::primitives::array::put_array_len(buf, (self.entity).len(), flex);
146                for it in &self.entity {
147                    it.encode(buf, version)?;
148                }
149            }
150        }
151        if flex {
152            let tagged = WriteTaggedFields::new();
153            tagged.write(buf, &self.unknown_tagged_fields);
154        }
155        Ok(())
156    }
157    fn encoded_len(&self, version: i16) -> usize {
158        let flex = version >= 1;
159        let mut n: usize = 0;
160        if version >= 0 {
161            n += 2;
162        }
163        if version >= 0 {
164            n += if flex {
165                compact_nullable_string_len(self.error_message.as_deref())
166            } else {
167                nullable_string_len(self.error_message.as_deref())
168            };
169        }
170        if version >= 0 {
171            n += {
172                let prefix =
173                    crate::primitives::array::array_len_prefix_len((self.entity).len(), flex);
174                let body: usize = (self.entity).iter().map(|it| it.encoded_len(version)).sum();
175                prefix + body
176            };
177        }
178        if flex {
179            let known_pairs: Vec<(u32, usize)> = Vec::new();
180            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
181        }
182        n
183    }
184}
185impl Decode<'_> for EntryData {
186    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
187        let flex = version >= 1;
188        let mut out = Self::default();
189        if version >= 0 {
190            out.error_code = get_i16(buf)?;
191        }
192        if version >= 0 {
193            out.error_message = if flex {
194                get_compact_nullable_string_owned(buf)?
195            } else {
196                get_nullable_string_owned(buf)?
197            };
198        }
199        if version >= 0 {
200            out.entity = {
201                let n = crate::primitives::array::get_array_len(buf, flex)?;
202                let mut v = Vec::with_capacity(n);
203                for _ in 0..n {
204                    v.push(EntityData::decode(buf, version)?);
205                }
206                v
207            };
208        }
209        if flex {
210            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
211        }
212        Ok(out)
213    }
214}
215#[cfg(test)]
216impl EntryData {
217    #[must_use]
218    pub fn populated(version: i16) -> Self {
219        let mut m = Self::default();
220        if version >= 0 {
221            m.error_code = 1i16;
222        }
223        if version >= 0 {
224            m.error_message = Some("x".to_string());
225        }
226        if version >= 0 {
227            m.entity = vec![EntityData::populated(version)];
228        }
229        m
230    }
231}
232#[derive(Debug, Clone, PartialEq, Eq, Default)]
233pub struct EntityData {
234    pub entity_type: String,
235    pub entity_name: Option<String>,
236    pub unknown_tagged_fields: UnknownTaggedFields,
237}
238impl Encode for EntityData {
239    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
240        let flex = version >= 1;
241        if version >= 0 {
242            if flex {
243                put_compact_string(buf, &self.entity_type);
244            } else {
245                put_string(buf, &self.entity_type);
246            }
247        }
248        if version >= 0 {
249            if flex {
250                put_compact_nullable_string(buf, self.entity_name.as_deref());
251            } else {
252                put_nullable_string(buf, self.entity_name.as_deref());
253            }
254        }
255        if flex {
256            let tagged = WriteTaggedFields::new();
257            tagged.write(buf, &self.unknown_tagged_fields);
258        }
259        Ok(())
260    }
261    fn encoded_len(&self, version: i16) -> usize {
262        let flex = version >= 1;
263        let mut n: usize = 0;
264        if version >= 0 {
265            n += if flex {
266                compact_string_len(&self.entity_type)
267            } else {
268                string_len(&self.entity_type)
269            };
270        }
271        if version >= 0 {
272            n += if flex {
273                compact_nullable_string_len(self.entity_name.as_deref())
274            } else {
275                nullable_string_len(self.entity_name.as_deref())
276            };
277        }
278        if flex {
279            let known_pairs: Vec<(u32, usize)> = Vec::new();
280            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
281        }
282        n
283    }
284}
285impl Decode<'_> for EntityData {
286    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
287        let flex = version >= 1;
288        let mut out = Self::default();
289        if version >= 0 {
290            out.entity_type = if flex {
291                get_compact_string_owned(buf)?
292            } else {
293                get_string_owned(buf)?
294            };
295        }
296        if version >= 0 {
297            out.entity_name = if flex {
298                get_compact_nullable_string_owned(buf)?
299            } else {
300                get_nullable_string_owned(buf)?
301            };
302        }
303        if flex {
304            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
305        }
306        Ok(out)
307    }
308}
309#[cfg(test)]
310impl EntityData {
311    #[must_use]
312    pub fn populated(version: i16) -> Self {
313        let mut m = Self::default();
314        if version >= 0 {
315            m.entity_type = "x".to_string();
316        }
317        if version >= 0 {
318            m.entity_name = Some("x".to_string());
319        }
320        m
321    }
322}
323
324/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
325/// Only includes fields valid for the given version.
326#[must_use]
327#[allow(unused_comparisons)]
328pub fn default_json(version: i16) -> ::serde_json::Value {
329    let mut obj = ::serde_json::Map::new();
330    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
331    obj.insert("entries".to_string(), ::serde_json::Value::Array(vec![]));
332    ::serde_json::Value::Object(obj)
333}