Skip to main content

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