Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
IncrementalAlterConfigsRequest.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_bool, get_i8, put_bool, put_i8};
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 = 44;
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 IncrementalAlterConfigsRequest {
26    pub resources: Vec<AlterConfigsResource>,
27    pub validate_only: bool,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for IncrementalAlterConfigsRequest {
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            {
41                crate::primitives::array::put_array_len(buf, (self.resources).len(), flex);
42                for it in &self.resources {
43                    it.encode(buf, version)?;
44                }
45            }
46        }
47        if version >= 0 {
48            put_bool(buf, self.validate_only);
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 += {
61                let prefix =
62                    crate::primitives::array::array_len_prefix_len((self.resources).len(), flex);
63                let body: usize = (self.resources)
64                    .iter()
65                    .map(|it| it.encoded_len(version))
66                    .sum();
67                prefix + body
68            };
69        }
70        if version >= 0 {
71            n += 1;
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 IncrementalAlterConfigsRequest {
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.resources = {
92                let n = crate::primitives::array::get_array_len(buf, flex)?;
93                let mut v = Vec::with_capacity(n);
94                for _ in 0..n {
95                    v.push(AlterConfigsResource::decode(buf, version)?);
96                }
97                v
98            };
99        }
100        if version >= 0 {
101            out.validate_only = get_bool(buf)?;
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 IncrementalAlterConfigsRequest {
111    #[must_use]
112    pub fn populated(version: i16) -> Self {
113        let mut m = Self::default();
114        if version >= 0 {
115            m.resources = vec![AlterConfigsResource::populated(version)];
116        }
117        if version >= 0 {
118            m.validate_only = true;
119        }
120        m
121    }
122}
123#[derive(Debug, Clone, PartialEq, Eq, Default)]
124pub struct AlterConfigsResource {
125    pub resource_type: i8,
126    pub resource_name: String,
127    pub configs: Vec<AlterableConfig>,
128    pub unknown_tagged_fields: UnknownTaggedFields,
129}
130impl Encode for AlterConfigsResource {
131    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
132        let flex = version >= 1;
133        if version >= 0 {
134            put_i8(buf, self.resource_type);
135        }
136        if version >= 0 {
137            if flex {
138                put_compact_string(buf, &self.resource_name);
139            } else {
140                put_string(buf, &self.resource_name);
141            }
142        }
143        if version >= 0 {
144            {
145                crate::primitives::array::put_array_len(buf, (self.configs).len(), flex);
146                for it in &self.configs {
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 += 1;
162        }
163        if version >= 0 {
164            n += if flex {
165                compact_string_len(&self.resource_name)
166            } else {
167                string_len(&self.resource_name)
168            };
169        }
170        if version >= 0 {
171            n += {
172                let prefix =
173                    crate::primitives::array::array_len_prefix_len((self.configs).len(), flex);
174                let body: usize = (self.configs)
175                    .iter()
176                    .map(|it| it.encoded_len(version))
177                    .sum();
178                prefix + body
179            };
180        }
181        if flex {
182            let known_pairs: Vec<(u32, usize)> = Vec::new();
183            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
184        }
185        n
186    }
187}
188impl Decode<'_> for AlterConfigsResource {
189    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
190        let flex = version >= 1;
191        let mut out = Self::default();
192        if version >= 0 {
193            out.resource_type = get_i8(buf)?;
194        }
195        if version >= 0 {
196            out.resource_name = if flex {
197                get_compact_string_owned(buf)?
198            } else {
199                get_string_owned(buf)?
200            };
201        }
202        if version >= 0 {
203            out.configs = {
204                let n = crate::primitives::array::get_array_len(buf, flex)?;
205                let mut v = Vec::with_capacity(n);
206                for _ in 0..n {
207                    v.push(AlterableConfig::decode(buf, version)?);
208                }
209                v
210            };
211        }
212        if flex {
213            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
214        }
215        Ok(out)
216    }
217}
218#[cfg(test)]
219impl AlterConfigsResource {
220    #[must_use]
221    pub fn populated(version: i16) -> Self {
222        let mut m = Self::default();
223        if version >= 0 {
224            m.resource_type = 1i8;
225        }
226        if version >= 0 {
227            m.resource_name = "x".to_string();
228        }
229        if version >= 0 {
230            m.configs = vec![AlterableConfig::populated(version)];
231        }
232        m
233    }
234}
235#[derive(Debug, Clone, PartialEq, Eq, Default)]
236pub struct AlterableConfig {
237    pub name: String,
238    pub config_operation: i8,
239    pub value: Option<String>,
240    pub unknown_tagged_fields: UnknownTaggedFields,
241}
242impl Encode for AlterableConfig {
243    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
244        let flex = version >= 1;
245        if version >= 0 {
246            if flex {
247                put_compact_string(buf, &self.name);
248            } else {
249                put_string(buf, &self.name);
250            }
251        }
252        if version >= 0 {
253            put_i8(buf, self.config_operation);
254        }
255        if version >= 0 {
256            if flex {
257                put_compact_nullable_string(buf, self.value.as_deref());
258            } else {
259                put_nullable_string(buf, self.value.as_deref());
260            }
261        }
262        if flex {
263            let tagged = WriteTaggedFields::new();
264            tagged.write(buf, &self.unknown_tagged_fields);
265        }
266        Ok(())
267    }
268    fn encoded_len(&self, version: i16) -> usize {
269        let flex = version >= 1;
270        let mut n: usize = 0;
271        if version >= 0 {
272            n += if flex {
273                compact_string_len(&self.name)
274            } else {
275                string_len(&self.name)
276            };
277        }
278        if version >= 0 {
279            n += 1;
280        }
281        if version >= 0 {
282            n += if flex {
283                compact_nullable_string_len(self.value.as_deref())
284            } else {
285                nullable_string_len(self.value.as_deref())
286            };
287        }
288        if flex {
289            let known_pairs: Vec<(u32, usize)> = Vec::new();
290            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
291        }
292        n
293    }
294}
295impl Decode<'_> for AlterableConfig {
296    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
297        let flex = version >= 1;
298        let mut out = Self::default();
299        if version >= 0 {
300            out.name = if flex {
301                get_compact_string_owned(buf)?
302            } else {
303                get_string_owned(buf)?
304            };
305        }
306        if version >= 0 {
307            out.config_operation = get_i8(buf)?;
308        }
309        if version >= 0 {
310            out.value = if flex {
311                get_compact_nullable_string_owned(buf)?
312            } else {
313                get_nullable_string_owned(buf)?
314            };
315        }
316        if flex {
317            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
318        }
319        Ok(out)
320    }
321}
322#[cfg(test)]
323impl AlterableConfig {
324    #[must_use]
325    pub fn populated(version: i16) -> Self {
326        let mut m = Self::default();
327        if version >= 0 {
328            m.name = "x".to_string();
329        }
330        if version >= 0 {
331            m.config_operation = 1i8;
332        }
333        if version >= 0 {
334            m.value = Some("x".to_string());
335        }
336        m
337    }
338}
339
340/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
341/// Only includes fields valid for the given version.
342#[must_use]
343#[allow(unused_comparisons)]
344pub fn default_json(version: i16) -> ::serde_json::Value {
345    let mut obj = ::serde_json::Map::new();
346    obj.insert("resources".to_string(), ::serde_json::Value::Array(vec![]));
347    obj.insert("validateOnly".to_string(), ::serde_json::Value::Bool(false));
348    ::serde_json::Value::Object(obj)
349}
350
351impl crate::ProtocolRequest for IncrementalAlterConfigsRequest {
352    const API_KEY: i16 = API_KEY;
353    const MIN_VERSION: i16 = MIN_VERSION;
354    const MAX_VERSION: i16 = MAX_VERSION;
355    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
356    type Response = super::incremental_alter_configs_response::IncrementalAlterConfigsResponse;
357}