Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterClientQuotasResponse.borrowed.rs

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