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