Skip to main content

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