Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i8, get_i32, get_i64, put_i8, put_i32, put_i64};
4use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
5use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
6use bytes::{Buf, BufMut};
7pub const API_KEY: i16 = 56;
8pub const MIN_VERSION: i16 = 2;
9pub const MAX_VERSION: i16 = 3;
10pub const FLEXIBLE_MIN: i16 = 0;
11#[inline]
12fn is_flexible(version: i16) -> bool {
13    version >= FLEXIBLE_MIN
14}
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct AlterPartitionRequest {
17    pub broker_id: i32,
18    pub broker_epoch: i64,
19    pub topics: Vec<TopicData>,
20    pub unknown_tagged_fields: UnknownTaggedFields,
21}
22impl Default for AlterPartitionRequest {
23    fn default() -> Self {
24        Self {
25            broker_id: 0i32,
26            broker_epoch: -1i64,
27            topics: Vec::new(),
28            unknown_tagged_fields: Default::default(),
29        }
30    }
31}
32impl Encode for AlterPartitionRequest {
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.broker_id);
43        }
44        if version >= 0 {
45            put_i64(buf, self.broker_epoch);
46        }
47        if version >= 0 {
48            {
49                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
50                for it in &self.topics {
51                    it.encode(buf, version)?;
52                }
53            }
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 += 4;
66        }
67        if version >= 0 {
68            n += 8;
69        }
70        if version >= 0 {
71            n += {
72                let prefix =
73                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
74                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
75                prefix + body
76            };
77        }
78        if flex {
79            let known_pairs: Vec<(u32, usize)> = Vec::new();
80            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
81        }
82        n
83    }
84}
85impl Decode<'_> for AlterPartitionRequest {
86    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
87        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
88            return Err(ProtocolError::UnsupportedVersion {
89                api_key: API_KEY,
90                version,
91            });
92        }
93        let flex = is_flexible(version);
94        let mut out = Self::default();
95        if version >= 0 {
96            out.broker_id = get_i32(buf)?;
97        }
98        if version >= 0 {
99            out.broker_epoch = get_i64(buf)?;
100        }
101        if version >= 0 {
102            out.topics = {
103                let n = crate::primitives::array::get_array_len(buf, flex)?;
104                let mut v = Vec::with_capacity(n);
105                for _ in 0..n {
106                    v.push(TopicData::decode(buf, version)?);
107                }
108                v
109            };
110        }
111        if flex {
112            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
113        }
114        Ok(out)
115    }
116}
117#[cfg(test)]
118impl AlterPartitionRequest {
119    #[must_use]
120    pub fn populated(version: i16) -> Self {
121        let mut m = Self::default();
122        if version >= 0 {
123            m.broker_id = 1i32;
124        }
125        if version >= 0 {
126            m.broker_epoch = 1i64;
127        }
128        if version >= 0 {
129            m.topics = vec![TopicData::populated(version)];
130        }
131        m
132    }
133}
134#[derive(Debug, Clone, PartialEq, Eq, Default)]
135pub struct TopicData {
136    pub topic_id: crate::primitives::uuid::Uuid,
137    pub partitions: Vec<PartitionData>,
138    pub unknown_tagged_fields: UnknownTaggedFields,
139}
140impl Encode for TopicData {
141    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
142        let flex = version >= 0;
143        if version >= 2 {
144            crate::primitives::uuid::put_uuid(buf, self.topic_id);
145        }
146        if version >= 0 {
147            {
148                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
149                for it in &self.partitions {
150                    it.encode(buf, version)?;
151                }
152            }
153        }
154        if flex {
155            let tagged = WriteTaggedFields::new();
156            tagged.write(buf, &self.unknown_tagged_fields);
157        }
158        Ok(())
159    }
160    fn encoded_len(&self, version: i16) -> usize {
161        let flex = version >= 0;
162        let mut n: usize = 0;
163        if version >= 2 {
164            n += 16;
165        }
166        if version >= 0 {
167            n += {
168                let prefix =
169                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
170                let body: usize = (self.partitions)
171                    .iter()
172                    .map(|it| it.encoded_len(version))
173                    .sum();
174                prefix + body
175            };
176        }
177        if flex {
178            let known_pairs: Vec<(u32, usize)> = Vec::new();
179            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
180        }
181        n
182    }
183}
184impl Decode<'_> for TopicData {
185    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
186        let flex = version >= 0;
187        let mut out = Self::default();
188        if version >= 2 {
189            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
190        }
191        if version >= 0 {
192            out.partitions = {
193                let n = crate::primitives::array::get_array_len(buf, flex)?;
194                let mut v = Vec::with_capacity(n);
195                for _ in 0..n {
196                    v.push(PartitionData::decode(buf, version)?);
197                }
198                v
199            };
200        }
201        if flex {
202            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
203        }
204        Ok(out)
205    }
206}
207#[cfg(test)]
208impl TopicData {
209    #[must_use]
210    pub fn populated(version: i16) -> Self {
211        let mut m = Self::default();
212        if version >= 2 {
213            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
214        }
215        if version >= 0 {
216            m.partitions = vec![PartitionData::populated(version)];
217        }
218        m
219    }
220}
221#[derive(Debug, Clone, PartialEq, Eq, Default)]
222pub struct PartitionData {
223    pub partition_index: i32,
224    pub leader_epoch: i32,
225    pub new_isr: Vec<i32>,
226    pub new_isr_with_epochs: Vec<BrokerState>,
227    pub leader_recovery_state: i8,
228    pub partition_epoch: i32,
229    pub unknown_tagged_fields: UnknownTaggedFields,
230}
231impl Encode for PartitionData {
232    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
233        let flex = version >= 0;
234        if version >= 0 {
235            put_i32(buf, self.partition_index);
236        }
237        if version >= 0 {
238            put_i32(buf, self.leader_epoch);
239        }
240        if (0..=2).contains(&version) {
241            {
242                crate::primitives::array::put_array_len(buf, (self.new_isr).len(), flex);
243                for it in &self.new_isr {
244                    put_i32(buf, *it);
245                }
246            }
247        }
248        if version >= 3 {
249            {
250                crate::primitives::array::put_array_len(
251                    buf,
252                    (self.new_isr_with_epochs).len(),
253                    flex,
254                );
255                for it in &self.new_isr_with_epochs {
256                    it.encode(buf, version)?;
257                }
258            }
259        }
260        if version >= 1 {
261            put_i8(buf, self.leader_recovery_state);
262        }
263        if version >= 0 {
264            put_i32(buf, self.partition_epoch);
265        }
266        if flex {
267            let tagged = WriteTaggedFields::new();
268            tagged.write(buf, &self.unknown_tagged_fields);
269        }
270        Ok(())
271    }
272    fn encoded_len(&self, version: i16) -> usize {
273        let flex = version >= 0;
274        let mut n: usize = 0;
275        if version >= 0 {
276            n += 4;
277        }
278        if version >= 0 {
279            n += 4;
280        }
281        if (0..=2).contains(&version) {
282            n += {
283                let prefix =
284                    crate::primitives::array::array_len_prefix_len((self.new_isr).len(), flex);
285                let body: usize = (self.new_isr).iter().map(|_| 4).sum();
286                prefix + body
287            };
288        }
289        if version >= 3 {
290            n += {
291                let prefix = crate::primitives::array::array_len_prefix_len(
292                    (self.new_isr_with_epochs).len(),
293                    flex,
294                );
295                let body: usize = (self.new_isr_with_epochs)
296                    .iter()
297                    .map(|it| it.encoded_len(version))
298                    .sum();
299                prefix + body
300            };
301        }
302        if version >= 1 {
303            n += 1;
304        }
305        if version >= 0 {
306            n += 4;
307        }
308        if flex {
309            let known_pairs: Vec<(u32, usize)> = Vec::new();
310            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
311        }
312        n
313    }
314}
315impl Decode<'_> for PartitionData {
316    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
317        let flex = version >= 0;
318        let mut out = Self::default();
319        if version >= 0 {
320            out.partition_index = get_i32(buf)?;
321        }
322        if version >= 0 {
323            out.leader_epoch = get_i32(buf)?;
324        }
325        if (0..=2).contains(&version) {
326            out.new_isr = {
327                let n = crate::primitives::array::get_array_len(buf, flex)?;
328                let mut v = Vec::with_capacity(n);
329                for _ in 0..n {
330                    v.push(get_i32(buf)?);
331                }
332                v
333            };
334        }
335        if version >= 3 {
336            out.new_isr_with_epochs = {
337                let n = crate::primitives::array::get_array_len(buf, flex)?;
338                let mut v = Vec::with_capacity(n);
339                for _ in 0..n {
340                    v.push(BrokerState::decode(buf, version)?);
341                }
342                v
343            };
344        }
345        if version >= 1 {
346            out.leader_recovery_state = get_i8(buf)?;
347        }
348        if version >= 0 {
349            out.partition_epoch = get_i32(buf)?;
350        }
351        if flex {
352            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
353        }
354        Ok(out)
355    }
356}
357#[cfg(test)]
358impl PartitionData {
359    #[must_use]
360    pub fn populated(version: i16) -> Self {
361        let mut m = Self::default();
362        if version >= 0 {
363            m.partition_index = 1i32;
364        }
365        if version >= 0 {
366            m.leader_epoch = 1i32;
367        }
368        if (0..=2).contains(&version) {
369            m.new_isr = vec![1i32];
370        }
371        if version >= 3 {
372            m.new_isr_with_epochs = vec![BrokerState::populated(version)];
373        }
374        if version >= 1 {
375            m.leader_recovery_state = 1i8;
376        }
377        if version >= 0 {
378            m.partition_epoch = 1i32;
379        }
380        m
381    }
382}
383#[derive(Debug, Clone, PartialEq, Eq)]
384pub struct BrokerState {
385    pub broker_id: i32,
386    pub broker_epoch: i64,
387    pub unknown_tagged_fields: UnknownTaggedFields,
388}
389impl Default for BrokerState {
390    fn default() -> Self {
391        Self {
392            broker_id: 0i32,
393            broker_epoch: -1i64,
394            unknown_tagged_fields: Default::default(),
395        }
396    }
397}
398impl Encode for BrokerState {
399    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
400        let flex = version >= 0;
401        if version >= 3 {
402            put_i32(buf, self.broker_id);
403        }
404        if version >= 3 {
405            put_i64(buf, self.broker_epoch);
406        }
407        if flex {
408            let tagged = WriteTaggedFields::new();
409            tagged.write(buf, &self.unknown_tagged_fields);
410        }
411        Ok(())
412    }
413    fn encoded_len(&self, version: i16) -> usize {
414        let flex = version >= 0;
415        let mut n: usize = 0;
416        if version >= 3 {
417            n += 4;
418        }
419        if version >= 3 {
420            n += 8;
421        }
422        if flex {
423            let known_pairs: Vec<(u32, usize)> = Vec::new();
424            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
425        }
426        n
427    }
428}
429impl Decode<'_> for BrokerState {
430    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
431        let flex = version >= 0;
432        let mut out = Self::default();
433        if version >= 3 {
434            out.broker_id = get_i32(buf)?;
435        }
436        if version >= 3 {
437            out.broker_epoch = get_i64(buf)?;
438        }
439        if flex {
440            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
441        }
442        Ok(out)
443    }
444}
445#[cfg(test)]
446impl BrokerState {
447    #[must_use]
448    pub fn populated(version: i16) -> Self {
449        let mut m = Self::default();
450        if version >= 3 {
451            m.broker_id = 1i32;
452        }
453        if version >= 3 {
454            m.broker_epoch = 1i64;
455        }
456        m
457    }
458}
459/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
460/// Only includes fields valid for the given version.
461#[must_use]
462#[allow(unused_comparisons)]
463pub fn default_json(version: i16) -> ::serde_json::Value {
464    let mut obj = ::serde_json::Map::new();
465    obj.insert("brokerId".to_string(), ::serde_json::json!(0));
466    obj.insert("brokerEpoch".to_string(), ::serde_json::json!(-1));
467    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
468    ::serde_json::Value::Object(obj)
469}
470impl crate::ProtocolRequest for AlterPartitionRequest {
471    const API_KEY: i16 = API_KEY;
472    const MIN_VERSION: i16 = MIN_VERSION;
473    const MAX_VERSION: i16 = MAX_VERSION;
474    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
475    type Response = super::alter_partition_response::AlterPartitionResponse;
476}