Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
IncrementalAlterConfigsRequest.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::incremental_alter_configs_request,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_bool, get_i8, put_bool, put_i8},
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 = 44;
23pub const MIN_VERSION: i16 = 0;
24pub const MAX_VERSION: i16 = 1;
25pub const LATEST_STABLE_VERSION: i16 = 1;
26pub const FLEXIBLE_MIN: i16 = 1;
27#[inline]
28#[must_use]
29pub fn is_flexible(version: i16) -> bool {
30    version >= FLEXIBLE_MIN
31}
32#[derive(Debug, Clone, PartialEq, Eq, Default)]
33pub struct IncrementalAlterConfigsRequest<'a> {
34    pub resources: Vec<AlterConfigsResource<'a>>,
35    pub validate_only: bool,
36    pub unknown_tagged_fields: UnknownTaggedFields,
37}
38impl IncrementalAlterConfigsRequest<'_> {
39    #[must_use]
40    pub fn to_owned(&self) -> incremental_alter_configs_request::IncrementalAlterConfigsRequest {
41        incremental_alter_configs_request::IncrementalAlterConfigsRequest {
42            resources: (self.resources)
43                .iter()
44                .map(AlterConfigsResource::to_owned)
45                .collect(),
46            validate_only: (self.validate_only),
47            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
48        }
49    }
50}
51impl Encode for IncrementalAlterConfigsRequest<'_> {
52    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
53        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
54            return Err(ProtocolError::UnsupportedVersion {
55                api_key: API_KEY,
56                version,
57            });
58        }
59        let flex = is_flexible(version);
60        if version >= 0 {
61            {
62                put_array_len(buf, (self.resources).len(), flex)?;
63                for it in &self.resources {
64                    it.encode(buf, version)?;
65                }
66            }
67        }
68        if version >= 0 {
69            put_bool(buf, self.validate_only);
70        }
71        if flex {
72            let tagged = WriteTaggedFields::new();
73            tagged.write(buf, &self.unknown_tagged_fields)?;
74        }
75        Ok(())
76    }
77    fn encoded_len(&self, version: i16) -> usize {
78        let flex = is_flexible(version);
79        let mut n: usize = 0;
80        if version >= 0 {
81            n += {
82                let prefix = array_len_prefix_len((self.resources).len(), flex);
83                let body: usize = (self.resources)
84                    .iter()
85                    .map(|it| it.encoded_len(version))
86                    .sum();
87                prefix + body
88            };
89        }
90        if version >= 0 {
91            n += 1;
92        }
93        if flex {
94            let known_pairs: Vec<(u32, usize)> = Vec::new();
95            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
96        }
97        n
98    }
99}
100impl<'de> DecodeBorrow<'de> for IncrementalAlterConfigsRequest<'de> {
101    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
102        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
103            return Err(ProtocolError::UnsupportedVersion {
104                api_key: API_KEY,
105                version,
106            });
107        }
108        let flex = is_flexible(version);
109        let mut out = Self::default();
110        if version >= 0 {
111            out.resources = {
112                let n = get_array_len(buf, flex)?;
113                let mut v = Vec::with_capacity(n);
114                for _ in 0..n {
115                    v.push(AlterConfigsResource::decode_borrow(buf, version)?);
116                }
117                v
118            };
119        }
120        if version >= 0 {
121            out.validate_only = get_bool(buf)?;
122        }
123        if flex {
124            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
125        }
126        Ok(out)
127    }
128}
129#[cfg(test)]
130impl IncrementalAlterConfigsRequest<'_> {
131    #[must_use]
132    pub fn populated(version: i16) -> Self {
133        let mut m = Self::default();
134        if version >= 0 {
135            m.resources = vec![AlterConfigsResource::populated(version)];
136        }
137        if version >= 0 {
138            m.validate_only = true;
139        }
140        m
141    }
142}
143#[derive(Debug, Clone, PartialEq, Eq, Default)]
144pub struct AlterConfigsResource<'a> {
145    pub resource_type: i8,
146    pub resource_name: &'a str,
147    pub configs: Vec<AlterableConfig<'a>>,
148    pub unknown_tagged_fields: UnknownTaggedFields,
149}
150impl AlterConfigsResource<'_> {
151    #[must_use]
152    pub fn to_owned(&self) -> incremental_alter_configs_request::AlterConfigsResource {
153        incremental_alter_configs_request::AlterConfigsResource {
154            resource_type: (self.resource_type),
155            resource_name: (self.resource_name).to_owned(),
156            configs: (self.configs)
157                .iter()
158                .map(AlterableConfig::to_owned)
159                .collect(),
160            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
161        }
162    }
163}
164impl Encode for AlterConfigsResource<'_> {
165    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
166        let flex = version >= 1;
167        if version >= 0 {
168            put_i8(buf, self.resource_type);
169        }
170        if version >= 0 {
171            if flex {
172                put_compact_string(buf, self.resource_name)?;
173            } else {
174                put_string(buf, self.resource_name)?;
175            }
176        }
177        if version >= 0 {
178            {
179                put_array_len(buf, (self.configs).len(), flex)?;
180                for it in &self.configs {
181                    it.encode(buf, version)?;
182                }
183            }
184        }
185        if flex {
186            let tagged = WriteTaggedFields::new();
187            tagged.write(buf, &self.unknown_tagged_fields)?;
188        }
189        Ok(())
190    }
191    fn encoded_len(&self, version: i16) -> usize {
192        let flex = version >= 1;
193        let mut n: usize = 0;
194        if version >= 0 {
195            n += 1;
196        }
197        if version >= 0 {
198            n += if flex {
199                compact_string_len(self.resource_name)
200            } else {
201                string_len(self.resource_name)
202            };
203        }
204        if version >= 0 {
205            n += {
206                let prefix = array_len_prefix_len((self.configs).len(), flex);
207                let body: usize = (self.configs)
208                    .iter()
209                    .map(|it| it.encoded_len(version))
210                    .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 AlterConfigsResource<'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.resource_type = get_i8(buf)?;
227        }
228        if version >= 0 {
229            out.resource_name = if flex {
230                get_compact_string_borrowed(buf)?
231            } else {
232                get_string_borrowed(buf)?
233            };
234        }
235        if version >= 0 {
236            out.configs = {
237                let n = get_array_len(buf, flex)?;
238                let mut v = Vec::with_capacity(n);
239                for _ in 0..n {
240                    v.push(AlterableConfig::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 AlterConfigsResource<'_> {
253    #[must_use]
254    pub fn populated(version: i16) -> Self {
255        let mut m = Self::default();
256        if version >= 0 {
257            m.resource_type = 1i8;
258        }
259        if version >= 0 {
260            m.resource_name = "x";
261        }
262        if version >= 0 {
263            m.configs = vec![AlterableConfig::populated(version)];
264        }
265        m
266    }
267}
268#[derive(Debug, Clone, PartialEq, Eq)]
269pub struct AlterableConfig<'a> {
270    pub name: &'a str,
271    pub config_operation: i8,
272    pub value: Option<&'a str>,
273    pub unknown_tagged_fields: UnknownTaggedFields,
274}
275impl Default for AlterableConfig<'_> {
276    fn default() -> Self {
277        Self {
278            name: "",
279            config_operation: 0i8,
280            value: Some(""),
281            unknown_tagged_fields: UnknownTaggedFields::default(),
282        }
283    }
284}
285impl AlterableConfig<'_> {
286    #[must_use]
287    pub fn to_owned(&self) -> incremental_alter_configs_request::AlterableConfig {
288        incremental_alter_configs_request::AlterableConfig {
289            name: (self.name).to_owned(),
290            config_operation: (self.config_operation),
291            value: (self.value).map(str::to_owned),
292            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
293        }
294    }
295}
296impl Encode for AlterableConfig<'_> {
297    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
298        let flex = version >= 1;
299        if version >= 0 {
300            if flex {
301                put_compact_string(buf, self.name)?;
302            } else {
303                put_string(buf, self.name)?;
304            }
305        }
306        if version >= 0 {
307            put_i8(buf, self.config_operation);
308        }
309        if version >= 0 {
310            if flex {
311                put_compact_nullable_string(buf, self.value)?;
312            } else {
313                put_nullable_string(buf, self.value)?;
314            }
315        }
316        if flex {
317            let tagged = WriteTaggedFields::new();
318            tagged.write(buf, &self.unknown_tagged_fields)?;
319        }
320        Ok(())
321    }
322    fn encoded_len(&self, version: i16) -> usize {
323        let flex = version >= 1;
324        let mut n: usize = 0;
325        if version >= 0 {
326            n += if flex {
327                compact_string_len(self.name)
328            } else {
329                string_len(self.name)
330            };
331        }
332        if version >= 0 {
333            n += 1;
334        }
335        if version >= 0 {
336            n += if flex {
337                compact_nullable_string_len(self.value)
338            } else {
339                nullable_string_len(self.value)
340            };
341        }
342        if flex {
343            let known_pairs: Vec<(u32, usize)> = Vec::new();
344            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
345        }
346        n
347    }
348}
349impl<'de> DecodeBorrow<'de> for AlterableConfig<'de> {
350    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
351        let flex = version >= 1;
352        let mut out = Self::default();
353        if version >= 0 {
354            out.name = if flex {
355                get_compact_string_borrowed(buf)?
356            } else {
357                get_string_borrowed(buf)?
358            };
359        }
360        if version >= 0 {
361            out.config_operation = get_i8(buf)?;
362        }
363        if version >= 0 {
364            out.value = if flex {
365                get_compact_nullable_string_borrowed(buf)?
366            } else {
367                get_nullable_string_borrowed(buf)?
368            };
369        }
370        if flex {
371            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
372        }
373        Ok(out)
374    }
375}
376#[cfg(test)]
377impl AlterableConfig<'_> {
378    #[must_use]
379    pub fn populated(version: i16) -> Self {
380        let mut m = Self::default();
381        if version >= 0 {
382            m.name = "x";
383        }
384        if version >= 0 {
385            m.config_operation = 1i8;
386        }
387        if version >= 0 {
388            m.value = Some("x");
389        }
390        m
391    }
392}