Skip to main content

kacrab_protocol/generated/
alter_partition_reassignments_response.rs

1//! Generated from AlterPartitionReassignmentsResponse.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 AlterPartitionReassignmentsResponseData {
17    /// The duration in milliseconds for which the request was throttled due to a quota violation,
18    /// or zero if the request did not violate any quota.
19    pub throttle_time_ms: i32,
20    /// The option indicating whether changing the replication factor of any given partition as
21    /// part of the request was allowed.
22    pub allow_replication_factor_change: bool,
23    /// The top-level error code, or 0 if there was no error.
24    pub error_code: i16,
25    /// The top-level error message, or null if there was no error.
26    pub error_message: Option<KafkaString>,
27    /// The responses to topics to reassign.
28    pub responses: Vec<ReassignableTopicResponse>,
29    pub _unknown_tagged_fields: Vec<RawTaggedField>,
30}
31impl Default for AlterPartitionReassignmentsResponseData {
32    fn default() -> Self {
33        Self {
34            throttle_time_ms: 0_i32,
35            allow_replication_factor_change: true,
36            error_code: 0_i16,
37            error_message: None,
38            responses: Vec::new(),
39            _unknown_tagged_fields: Vec::new(),
40        }
41    }
42}
43impl AlterPartitionReassignmentsResponseData {
44    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
45        self.throttle_time_ms = value;
46        self
47    }
48    pub fn with_allow_replication_factor_change(mut self, value: bool) -> Self {
49        self.allow_replication_factor_change = value;
50        self
51    }
52    pub fn with_error_code(mut self, value: i16) -> Self {
53        self.error_code = value;
54        self
55    }
56    pub fn with_error_message(mut self, value: Option<KafkaString>) -> Self {
57        self.error_message = value;
58        self
59    }
60    pub fn with_responses(mut self, value: Vec<ReassignableTopicResponse>) -> Self {
61        self.responses = value;
62        self
63    }
64    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
65        if version < 0 || version > 1 {
66            return Err(UnsupportedVersion::new(45, version).into());
67        }
68        let throttle_time_ms;
69        let mut allow_replication_factor_change = true;
70        let error_code;
71        let error_message;
72        let responses;
73        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
74        throttle_time_ms = read_i32(buf)?;
75        if version >= 1 {
76            allow_replication_factor_change = read_bool(buf)?;
77        }
78        error_code = read_i16(buf)?;
79        error_message = read_compact_nullable_string(buf)?;
80        responses = {
81            let len = read_compact_array_length(buf)?;
82            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
83            for _ in 0..len {
84                arr.push(ReassignableTopicResponse::read(buf, version)?);
85            }
86            arr
87        };
88        let tagged_fields = read_tagged_fields(buf)?;
89        for field in &tagged_fields {
90            match field.tag {
91                _ => {
92                    _unknown_tagged_fields.push(field.clone());
93                },
94            }
95        }
96        Ok(Self {
97            throttle_time_ms,
98            allow_replication_factor_change,
99            error_code,
100            error_message,
101            responses,
102            _unknown_tagged_fields,
103        })
104    }
105    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
106        if version < 0 || version > 1 {
107            return Err(UnsupportedVersion::new(45, version).into());
108        }
109        write_i32(buf, self.throttle_time_ms);
110        if version >= 1 {
111            write_bool(buf, self.allow_replication_factor_change);
112        } else if self.allow_replication_factor_change != true {
113            return Err(UnsupportedFieldVersion::new(
114                45,
115                "allow_replication_factor_change",
116                version,
117            )
118            .into());
119        }
120        write_i16(buf, self.error_code);
121        write_compact_nullable_string(buf, self.error_message.as_ref())?;
122        write_compact_array_length(buf, self.responses.len() as i32);
123        for el in &self.responses {
124            el.write(buf, version)?;
125        }
126        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
127        all_tags.sort_by_key(|f| f.tag);
128        write_tagged_fields(buf, &all_tags)?;
129        Ok(())
130    }
131    pub fn encoded_len(&self, version: i16) -> Result<usize> {
132        if version < 0 || version > 1 {
133            return Err(UnsupportedVersion::new(45, version).into());
134        }
135        let mut len: usize = 0;
136        len += 4;
137        if version >= 1 {
138            len += 1;
139        } else if self.allow_replication_factor_change != true {
140            return Err(UnsupportedFieldVersion::new(
141                45,
142                "allow_replication_factor_change",
143                version,
144            )
145            .into());
146        }
147        len += 2;
148        len += compact_nullable_string_len(self.error_message.as_ref())?;
149        len += compact_array_length_len(self.responses.len() as i32);
150        for el in &self.responses {
151            len += el.encoded_len(version)?;
152        }
153        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
154        all_tags.sort_by_key(|f| f.tag);
155        len += tagged_fields_len(&all_tags)?;
156        Ok(len)
157    }
158}
159#[derive(Debug, Clone, PartialEq)]
160pub struct ReassignableTopicResponse {
161    /// The topic name.
162    pub name: KafkaString,
163    /// The responses to partitions to reassign.
164    pub partitions: Vec<ReassignablePartitionResponse>,
165    pub _unknown_tagged_fields: Vec<RawTaggedField>,
166}
167impl Default for ReassignableTopicResponse {
168    fn default() -> Self {
169        Self {
170            name: KafkaString::default(),
171            partitions: Vec::new(),
172            _unknown_tagged_fields: Vec::new(),
173        }
174    }
175}
176impl ReassignableTopicResponse {
177    pub fn with_name(mut self, value: KafkaString) -> Self {
178        self.name = value;
179        self
180    }
181    pub fn with_partitions(mut self, value: Vec<ReassignablePartitionResponse>) -> Self {
182        self.partitions = value;
183        self
184    }
185    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
186        let name;
187        let partitions;
188        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
189        name = read_compact_string(buf)?;
190        partitions = {
191            let len = read_compact_array_length(buf)?;
192            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
193            for _ in 0..len {
194                arr.push(ReassignablePartitionResponse::read(buf, version)?);
195            }
196            arr
197        };
198        let tagged_fields = read_tagged_fields(buf)?;
199        for field in &tagged_fields {
200            match field.tag {
201                _ => {
202                    _unknown_tagged_fields.push(field.clone());
203                },
204            }
205        }
206        Ok(Self {
207            name,
208            partitions,
209            _unknown_tagged_fields,
210        })
211    }
212    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
213        write_compact_string(buf, &self.name)?;
214        write_compact_array_length(buf, self.partitions.len() as i32);
215        for el in &self.partitions {
216            el.write(buf, version)?;
217        }
218        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
219        all_tags.sort_by_key(|f| f.tag);
220        write_tagged_fields(buf, &all_tags)?;
221        Ok(())
222    }
223    pub fn encoded_len(&self, version: i16) -> Result<usize> {
224        let mut len: usize = 0;
225        len += compact_string_len(&self.name)?;
226        len += compact_array_length_len(self.partitions.len() as i32);
227        for el in &self.partitions {
228            len += el.encoded_len(version)?;
229        }
230        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
231        all_tags.sort_by_key(|f| f.tag);
232        len += tagged_fields_len(&all_tags)?;
233        Ok(len)
234    }
235}
236#[derive(Debug, Clone, PartialEq)]
237pub struct ReassignablePartitionResponse {
238    /// The partition index.
239    pub partition_index: i32,
240    /// The error code for this partition, or 0 if there was no error.
241    pub error_code: i16,
242    /// The error message for this partition, or null if there was no error.
243    pub error_message: Option<KafkaString>,
244    pub _unknown_tagged_fields: Vec<RawTaggedField>,
245}
246impl Default for ReassignablePartitionResponse {
247    fn default() -> Self {
248        Self {
249            partition_index: 0_i32,
250            error_code: 0_i16,
251            error_message: None,
252            _unknown_tagged_fields: Vec::new(),
253        }
254    }
255}
256impl ReassignablePartitionResponse {
257    pub fn with_partition_index(mut self, value: i32) -> Self {
258        self.partition_index = value;
259        self
260    }
261    pub fn with_error_code(mut self, value: i16) -> Self {
262        self.error_code = value;
263        self
264    }
265    pub fn with_error_message(mut self, value: Option<KafkaString>) -> Self {
266        self.error_message = value;
267        self
268    }
269    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
270        let partition_index;
271        let error_code;
272        let error_message;
273        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
274        partition_index = read_i32(buf)?;
275        error_code = read_i16(buf)?;
276        error_message = read_compact_nullable_string(buf)?;
277        let tagged_fields = read_tagged_fields(buf)?;
278        for field in &tagged_fields {
279            match field.tag {
280                _ => {
281                    _unknown_tagged_fields.push(field.clone());
282                },
283            }
284        }
285        Ok(Self {
286            partition_index,
287            error_code,
288            error_message,
289            _unknown_tagged_fields,
290        })
291    }
292    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
293        write_i32(buf, self.partition_index);
294        write_i16(buf, self.error_code);
295        write_compact_nullable_string(buf, self.error_message.as_ref())?;
296        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
297        all_tags.sort_by_key(|f| f.tag);
298        write_tagged_fields(buf, &all_tags)?;
299        Ok(())
300    }
301    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
302        let mut len: usize = 0;
303        len += 4;
304        len += 2;
305        len += compact_nullable_string_len(self.error_message.as_ref())?;
306        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
307        all_tags.sort_by_key(|f| f.tag);
308        len += tagged_fields_len(&all_tags)?;
309        Ok(len)
310    }
311}