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