Skip to main content

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