Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AlterConfigsRequest.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 = 33;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 2;
21pub const LATEST_STABLE_VERSION: i16 = 2;
22pub const FLEXIBLE_MIN: i16 = 2;
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 AlterConfigsRequest {
30    pub resources: Vec<AlterConfigsResource>,
31    pub validate_only: bool,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for AlterConfigsRequest {
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 AlterConfigsRequest {
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 AlterConfigsRequest {
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 >= 2;
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 >= 2;
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 >= 2;
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 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            value: Some(String::new()),
250            unknown_tagged_fields: UnknownTaggedFields::default(),
251        }
252    }
253}
254impl Encode for AlterableConfig {
255    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
256        let flex = version >= 2;
257        if version >= 0 {
258            if flex {
259                let () = put_compact_string(buf, &self.name);
260            } else {
261                let () = put_string(buf, &self.name);
262            }
263        }
264        if version >= 0 {
265            if flex {
266                let () = put_compact_nullable_string(buf, self.value.as_deref());
267            } else {
268                let () = put_nullable_string(buf, self.value.as_deref());
269            }
270        }
271        if flex {
272            let tagged = WriteTaggedFields::new();
273            tagged.write(buf, &self.unknown_tagged_fields);
274        }
275        Ok(())
276    }
277    fn encoded_len(&self, version: i16) -> usize {
278        let flex = version >= 2;
279        let mut n: usize = 0;
280        if version >= 0 {
281            n += if flex {
282                compact_string_len(&self.name)
283            } else {
284                string_len(&self.name)
285            };
286        }
287        if version >= 0 {
288            n += if flex {
289                compact_nullable_string_len(self.value.as_deref())
290            } else {
291                nullable_string_len(self.value.as_deref())
292            };
293        }
294        if flex {
295            let known_pairs: Vec<(u32, usize)> = Vec::new();
296            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
297        }
298        n
299    }
300}
301impl Decode<'_> for AlterableConfig {
302    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
303        let flex = version >= 2;
304        let mut out = Self::default();
305        if version >= 0 {
306            out.name = if flex {
307                get_compact_string_owned(buf)?
308            } else {
309                get_string_owned(buf)?
310            };
311        }
312        if version >= 0 {
313            out.value = if flex {
314                get_compact_nullable_string_owned(buf)?
315            } else {
316                get_nullable_string_owned(buf)?
317            };
318        }
319        if flex {
320            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
321        }
322        Ok(out)
323    }
324}
325#[cfg(test)]
326impl AlterableConfig {
327    #[must_use]
328    pub fn populated(version: i16) -> Self {
329        let mut m = Self::default();
330        if version >= 0 {
331            m.name = "x".to_string();
332        }
333        if version >= 0 {
334            m.value = Some("x".to_string());
335        }
336        m
337    }
338}
339/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
340/// Only includes fields valid for the given version.
341#[must_use]
342#[allow(unused_comparisons)]
343pub fn default_json(_version: i16) -> ::serde_json::Value {
344    let mut obj = ::serde_json::Map::new();
345    obj.insert("resources".to_string(), ::serde_json::Value::Array(vec![]));
346    obj.insert("validateOnly".to_string(), ::serde_json::Value::Bool(false));
347    ::serde_json::Value::Object(obj)
348}
349impl crate::ProtocolRequest for AlterConfigsRequest {
350    const API_KEY: i16 = API_KEY;
351    const MIN_VERSION: i16 = MIN_VERSION;
352    const MAX_VERSION: i16 = MAX_VERSION;
353    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
354    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
355    type Response = super::alter_configs_response::AlterConfigsResponse;
356}