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        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, get_compact_nullable_string_owned,
12            get_compact_string_owned, get_nullable_string_owned, get_string_owned,
13            nullable_string_len, put_compact_nullable_string, put_compact_string,
14            put_nullable_string, put_string, string_len,
15        },
16    },
17    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 44;
20pub const MIN_VERSION: i16 = 0;
21pub const MAX_VERSION: i16 = 1;
22pub const LATEST_STABLE_VERSION: i16 = 1;
23pub const FLEXIBLE_MIN: i16 = 1;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27    version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq, Default)]
30pub struct IncrementalAlterConfigsRequest {
31    pub resources: Vec<AlterConfigsResource>,
32    pub validate_only: bool,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl Encode for IncrementalAlterConfigsRequest {
36    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
37        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
38            return Err(ProtocolError::UnsupportedVersion {
39                api_key: API_KEY,
40                version,
41            });
42        }
43        let flex = is_flexible(version);
44        if version >= 0 {
45            {
46                put_array_len(buf, (self.resources).len(), flex)?;
47                for it in &self.resources {
48                    it.encode(buf, version)?;
49                }
50            }
51        }
52        if version >= 0 {
53            put_bool(buf, self.validate_only);
54        }
55        if flex {
56            let tagged = WriteTaggedFields::new();
57            tagged.write(buf, &self.unknown_tagged_fields)?;
58        }
59        Ok(())
60    }
61    fn encoded_len(&self, version: i16) -> usize {
62        let flex = is_flexible(version);
63        let mut n: usize = 0;
64        if version >= 0 {
65            n += {
66                let prefix = 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 = 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                put_compact_string(buf, &self.resource_name)?;
143            } else {
144                put_string(buf, &self.resource_name)?;
145            }
146        }
147        if version >= 0 {
148            {
149                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 = array_len_prefix_len((self.configs).len(), flex);
177                let body: usize = (self.configs)
178                    .iter()
179                    .map(|it| it.encoded_len(version))
180                    .sum();
181                prefix + body
182            };
183        }
184        if flex {
185            let known_pairs: Vec<(u32, usize)> = Vec::new();
186            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
187        }
188        n
189    }
190}
191impl Decode<'_> for AlterConfigsResource {
192    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
193        let flex = version >= 1;
194        let mut out = Self::default();
195        if version >= 0 {
196            out.resource_type = get_i8(buf)?;
197        }
198        if version >= 0 {
199            out.resource_name = if flex {
200                get_compact_string_owned(buf)?
201            } else {
202                get_string_owned(buf)?
203            };
204        }
205        if version >= 0 {
206            out.configs = {
207                let n = get_array_len(buf, flex)?;
208                let mut v = Vec::with_capacity(n);
209                for _ in 0..n {
210                    v.push(AlterableConfig::decode(buf, version)?);
211                }
212                v
213            };
214        }
215        if flex {
216            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
217        }
218        Ok(out)
219    }
220}
221#[cfg(test)]
222impl AlterConfigsResource {
223    #[must_use]
224    pub fn populated(version: i16) -> Self {
225        let mut m = Self::default();
226        if version >= 0 {
227            m.resource_type = 1i8;
228        }
229        if version >= 0 {
230            m.resource_name = "x".to_owned();
231        }
232        if version >= 0 {
233            m.configs = vec![AlterableConfig::populated(version)];
234        }
235        m
236    }
237}
238#[derive(Debug, Clone, PartialEq, Eq)]
239pub struct AlterableConfig {
240    pub name: String,
241    pub config_operation: i8,
242    pub value: Option<String>,
243    pub unknown_tagged_fields: UnknownTaggedFields,
244}
245impl Default for AlterableConfig {
246    fn default() -> Self {
247        Self {
248            name: String::new(),
249            config_operation: 0i8,
250            value: Some(String::new()),
251            unknown_tagged_fields: UnknownTaggedFields::default(),
252        }
253    }
254}
255impl Encode for AlterableConfig {
256    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
257        let flex = version >= 1;
258        if version >= 0 {
259            if flex {
260                put_compact_string(buf, &self.name)?;
261            } else {
262                put_string(buf, &self.name)?;
263            }
264        }
265        if version >= 0 {
266            put_i8(buf, self.config_operation);
267        }
268        if version >= 0 {
269            if flex {
270                put_compact_nullable_string(buf, self.value.as_deref())?;
271            } else {
272                put_nullable_string(buf, self.value.as_deref())?;
273            }
274        }
275        if flex {
276            let tagged = WriteTaggedFields::new();
277            tagged.write(buf, &self.unknown_tagged_fields)?;
278        }
279        Ok(())
280    }
281    fn encoded_len(&self, version: i16) -> usize {
282        let flex = version >= 1;
283        let mut n: usize = 0;
284        if version >= 0 {
285            n += if flex {
286                compact_string_len(&self.name)
287            } else {
288                string_len(&self.name)
289            };
290        }
291        if version >= 0 {
292            n += 1;
293        }
294        if version >= 0 {
295            n += if flex {
296                compact_nullable_string_len(self.value.as_deref())
297            } else {
298                nullable_string_len(self.value.as_deref())
299            };
300        }
301        if flex {
302            let known_pairs: Vec<(u32, usize)> = Vec::new();
303            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
304        }
305        n
306    }
307}
308impl Decode<'_> for AlterableConfig {
309    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
310        let flex = version >= 1;
311        let mut out = Self::default();
312        if version >= 0 {
313            out.name = if flex {
314                get_compact_string_owned(buf)?
315            } else {
316                get_string_owned(buf)?
317            };
318        }
319        if version >= 0 {
320            out.config_operation = get_i8(buf)?;
321        }
322        if version >= 0 {
323            out.value = if flex {
324                get_compact_nullable_string_owned(buf)?
325            } else {
326                get_nullable_string_owned(buf)?
327            };
328        }
329        if flex {
330            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
331        }
332        Ok(out)
333    }
334}
335#[cfg(test)]
336impl AlterableConfig {
337    #[must_use]
338    pub fn populated(version: i16) -> Self {
339        let mut m = Self::default();
340        if version >= 0 {
341            m.name = "x".to_owned();
342        }
343        if version >= 0 {
344            m.config_operation = 1i8;
345        }
346        if version >= 0 {
347            m.value = Some("x".to_owned());
348        }
349        m
350    }
351}
352/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
353/// Only includes fields valid for the given version.
354#[must_use]
355#[allow(unused_comparisons)]
356pub fn default_json(_version: i16) -> ::serde_json::Value {
357    let mut obj = ::serde_json::Map::new();
358    obj.insert("resources".to_owned(), ::serde_json::Value::Array(vec![]));
359    obj.insert("validateOnly".to_owned(), ::serde_json::Value::Bool(false));
360    ::serde_json::Value::Object(obj)
361}
362impl crate::ProtocolRequest for IncrementalAlterConfigsRequest {
363    const API_KEY: i16 = API_KEY;
364    const MIN_VERSION: i16 = MIN_VERSION;
365    const MAX_VERSION: i16 = MAX_VERSION;
366    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
367    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
368    type Response = super::incremental_alter_configs_response::IncrementalAlterConfigsResponse;
369}