Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
IncrementalAlterConfigsRequest.owned.rs

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