Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionRequest.borrowed.rs

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