Skip to main content

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

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