Skip to main content

kacrab_protocol/generated/
alter_partition_reassignments_request.rs

1//! Generated from AlterPartitionReassignmentsRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct AlterPartitionReassignmentsRequestData {
17    /// The time in ms to wait for the request to complete.
18    pub timeout_ms: i32,
19    /// The option indicating whether changing the replication factor of any given partition as
20    /// part of this request is a valid move.
21    pub allow_replication_factor_change: bool,
22    /// The topics to reassign.
23    pub topics: Vec<ReassignableTopic>,
24    pub _unknown_tagged_fields: Vec<RawTaggedField>,
25}
26impl Default for AlterPartitionReassignmentsRequestData {
27    fn default() -> Self {
28        Self {
29            timeout_ms: 60000i32,
30            allow_replication_factor_change: true,
31            topics: Vec::new(),
32            _unknown_tagged_fields: Vec::new(),
33        }
34    }
35}
36impl AlterPartitionReassignmentsRequestData {
37    pub fn with_timeout_ms(mut self, value: i32) -> Self {
38        self.timeout_ms = value;
39        self
40    }
41    pub fn with_allow_replication_factor_change(mut self, value: bool) -> Self {
42        self.allow_replication_factor_change = value;
43        self
44    }
45    pub fn with_topics(mut self, value: Vec<ReassignableTopic>) -> Self {
46        self.topics = value;
47        self
48    }
49    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
50        if version < 0 || version > 1 {
51            return Err(UnsupportedVersion::new(45, version).into());
52        }
53        let timeout_ms;
54        let mut allow_replication_factor_change = true;
55        let topics;
56        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
57        timeout_ms = read_i32(buf)?;
58        if version >= 1 {
59            allow_replication_factor_change = read_bool(buf)?;
60        }
61        topics = {
62            let len = read_compact_array_length(buf)?;
63            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
64            for _ in 0..len {
65                arr.push(ReassignableTopic::read(buf, version)?);
66            }
67            arr
68        };
69        let tagged_fields = read_tagged_fields(buf)?;
70        for field in &tagged_fields {
71            match field.tag {
72                _ => {
73                    _unknown_tagged_fields.push(field.clone());
74                },
75            }
76        }
77        Ok(Self {
78            timeout_ms,
79            allow_replication_factor_change,
80            topics,
81            _unknown_tagged_fields,
82        })
83    }
84    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
85        if version < 0 || version > 1 {
86            return Err(UnsupportedVersion::new(45, version).into());
87        }
88        write_i32(buf, self.timeout_ms);
89        if version >= 1 {
90            write_bool(buf, self.allow_replication_factor_change);
91        } else if self.allow_replication_factor_change != true {
92            return Err(UnsupportedFieldVersion::new(
93                45,
94                "allow_replication_factor_change",
95                version,
96            )
97            .into());
98        }
99        write_compact_array_length(buf, self.topics.len() as i32);
100        for el in &self.topics {
101            el.write(buf, version)?;
102        }
103        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
104        all_tags.sort_by_key(|f| f.tag);
105        write_tagged_fields(buf, &all_tags)?;
106        Ok(())
107    }
108    pub fn encoded_len(&self, version: i16) -> Result<usize> {
109        if version < 0 || version > 1 {
110            return Err(UnsupportedVersion::new(45, version).into());
111        }
112        let mut len: usize = 0;
113        len += 4;
114        if version >= 1 {
115            len += 1;
116        } else if self.allow_replication_factor_change != true {
117            return Err(UnsupportedFieldVersion::new(
118                45,
119                "allow_replication_factor_change",
120                version,
121            )
122            .into());
123        }
124        len += compact_array_length_len(self.topics.len() as i32);
125        for el in &self.topics {
126            len += el.encoded_len(version)?;
127        }
128        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
129        all_tags.sort_by_key(|f| f.tag);
130        len += tagged_fields_len(&all_tags)?;
131        Ok(len)
132    }
133}
134#[derive(Debug, Clone, PartialEq)]
135pub struct ReassignableTopic {
136    /// The topic name.
137    pub name: KafkaString,
138    /// The partitions to reassign.
139    pub partitions: Vec<ReassignablePartition>,
140    pub _unknown_tagged_fields: Vec<RawTaggedField>,
141}
142impl Default for ReassignableTopic {
143    fn default() -> Self {
144        Self {
145            name: KafkaString::default(),
146            partitions: Vec::new(),
147            _unknown_tagged_fields: Vec::new(),
148        }
149    }
150}
151impl ReassignableTopic {
152    pub fn with_name(mut self, value: KafkaString) -> Self {
153        self.name = value;
154        self
155    }
156    pub fn with_partitions(mut self, value: Vec<ReassignablePartition>) -> Self {
157        self.partitions = value;
158        self
159    }
160    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
161        let name;
162        let partitions;
163        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
164        name = read_compact_string(buf)?;
165        partitions = {
166            let len = read_compact_array_length(buf)?;
167            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
168            for _ in 0..len {
169                arr.push(ReassignablePartition::read(buf, version)?);
170            }
171            arr
172        };
173        let tagged_fields = read_tagged_fields(buf)?;
174        for field in &tagged_fields {
175            match field.tag {
176                _ => {
177                    _unknown_tagged_fields.push(field.clone());
178                },
179            }
180        }
181        Ok(Self {
182            name,
183            partitions,
184            _unknown_tagged_fields,
185        })
186    }
187    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
188        write_compact_string(buf, &self.name)?;
189        write_compact_array_length(buf, self.partitions.len() as i32);
190        for el in &self.partitions {
191            el.write(buf, version)?;
192        }
193        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
194        all_tags.sort_by_key(|f| f.tag);
195        write_tagged_fields(buf, &all_tags)?;
196        Ok(())
197    }
198    pub fn encoded_len(&self, version: i16) -> Result<usize> {
199        let mut len: usize = 0;
200        len += compact_string_len(&self.name)?;
201        len += compact_array_length_len(self.partitions.len() as i32);
202        for el in &self.partitions {
203            len += el.encoded_len(version)?;
204        }
205        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
206        all_tags.sort_by_key(|f| f.tag);
207        len += tagged_fields_len(&all_tags)?;
208        Ok(len)
209    }
210}
211#[derive(Debug, Clone, PartialEq)]
212pub struct ReassignablePartition {
213    /// The partition index.
214    pub partition_index: i32,
215    /// The replicas to place the partitions on, or null to cancel a pending reassignment for this
216    /// partition.
217    pub replicas: Option<Vec<i32>>,
218    pub _unknown_tagged_fields: Vec<RawTaggedField>,
219}
220impl Default for ReassignablePartition {
221    fn default() -> Self {
222        Self {
223            partition_index: 0_i32,
224            replicas: None,
225            _unknown_tagged_fields: Vec::new(),
226        }
227    }
228}
229impl ReassignablePartition {
230    pub fn with_partition_index(mut self, value: i32) -> Self {
231        self.partition_index = value;
232        self
233    }
234    pub fn with_replicas(mut self, value: Option<Vec<i32>>) -> Self {
235        self.replicas = value;
236        self
237    }
238    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
239        let partition_index;
240        let replicas;
241        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
242        partition_index = read_i32(buf)?;
243        replicas = {
244            let len = read_compact_array_length(buf)?;
245            if len < 0 {
246                None
247            } else {
248                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
249                for _ in 0..len {
250                    arr.push(read_i32(buf)?);
251                }
252                Some(arr)
253            }
254        };
255        let tagged_fields = read_tagged_fields(buf)?;
256        for field in &tagged_fields {
257            match field.tag {
258                _ => {
259                    _unknown_tagged_fields.push(field.clone());
260                },
261            }
262        }
263        Ok(Self {
264            partition_index,
265            replicas,
266            _unknown_tagged_fields,
267        })
268    }
269    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
270        write_i32(buf, self.partition_index);
271        match &self.replicas {
272            None => {
273                write_compact_array_length(buf, -1);
274            },
275            Some(arr) => {
276                write_compact_array_length(buf, arr.len() as i32);
277                for el in arr {
278                    write_i32(buf, *el);
279                }
280            },
281        }
282        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
283        all_tags.sort_by_key(|f| f.tag);
284        write_tagged_fields(buf, &all_tags)?;
285        Ok(())
286    }
287    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
288        let mut len: usize = 0;
289        len += 4;
290        match &self.replicas {
291            None => {
292                len += compact_array_length_len(-1);
293            },
294            Some(arr) => {
295                len += compact_array_length_len(arr.len() as i32);
296                len += arr.len() * 4usize;
297            },
298        }
299        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
300        all_tags.sort_by_key(|f| f.tag);
301        len += tagged_fields_len(&all_tags)?;
302        Ok(len)
303    }
304}