Skip to main content

kacrab_protocol/generated/
elect_leaders_response.rs

1//! Generated from ElectLeadersResponse.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 ElectLeadersResponseData {
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 top level response error code.
21    pub error_code: i16,
22    /// The election results, or an empty array if the requester did not have permission and the
23    /// request asks for all partitions.
24    pub replica_election_results: Vec<ReplicaElectionResult>,
25    pub _unknown_tagged_fields: Vec<RawTaggedField>,
26}
27impl Default for ElectLeadersResponseData {
28    fn default() -> Self {
29        Self {
30            throttle_time_ms: 0_i32,
31            error_code: 0_i16,
32            replica_election_results: Vec::new(),
33            _unknown_tagged_fields: Vec::new(),
34        }
35    }
36}
37impl ElectLeadersResponseData {
38    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
39        self.throttle_time_ms = value;
40        self
41    }
42    pub fn with_error_code(mut self, value: i16) -> Self {
43        self.error_code = value;
44        self
45    }
46    pub fn with_replica_election_results(mut self, value: Vec<ReplicaElectionResult>) -> Self {
47        self.replica_election_results = value;
48        self
49    }
50    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
51        if version < 0 || version > 2 {
52            return Err(UnsupportedVersion::new(43, version).into());
53        }
54        let throttle_time_ms;
55        let mut error_code = 0_i16;
56        let replica_election_results;
57        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
58        throttle_time_ms = read_i32(buf)?;
59        if version >= 1 {
60            error_code = read_i16(buf)?;
61        }
62        if version >= 2 {
63            replica_election_results = {
64                let len = read_compact_array_length(buf)?;
65                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
66                for _ in 0..len {
67                    arr.push(ReplicaElectionResult::read(buf, version)?);
68                }
69                arr
70            };
71        } else {
72            replica_election_results = {
73                let len = read_array_length(buf)?;
74                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
75                for _ in 0..len {
76                    arr.push(ReplicaElectionResult::read(buf, version)?);
77                }
78                arr
79            };
80        }
81        if version >= 2 {
82            let tagged_fields = read_tagged_fields(buf)?;
83            for field in &tagged_fields {
84                match field.tag {
85                    _ => {
86                        _unknown_tagged_fields.push(field.clone());
87                    },
88                }
89            }
90        }
91        Ok(Self {
92            throttle_time_ms,
93            error_code,
94            replica_election_results,
95            _unknown_tagged_fields,
96        })
97    }
98    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
99        if version < 0 || version > 2 {
100            return Err(UnsupportedVersion::new(43, version).into());
101        }
102        write_i32(buf, self.throttle_time_ms);
103        if version >= 1 {
104            write_i16(buf, self.error_code);
105        } else if self.error_code != 0_i16 {
106            return Err(UnsupportedFieldVersion::new(43, "error_code", version).into());
107        }
108        if version >= 2 {
109            write_compact_array_length(buf, self.replica_election_results.len() as i32);
110            for el in &self.replica_election_results {
111                el.write(buf, version)?;
112            }
113        } else {
114            write_array_length(buf, self.replica_election_results.len() as i32);
115            for el in &self.replica_election_results {
116                el.write(buf, version)?;
117            }
118        }
119        if version >= 2 {
120            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
121            all_tags.sort_by_key(|f| f.tag);
122            write_tagged_fields(buf, &all_tags)?;
123        }
124        Ok(())
125    }
126    pub fn encoded_len(&self, version: i16) -> Result<usize> {
127        if version < 0 || version > 2 {
128            return Err(UnsupportedVersion::new(43, version).into());
129        }
130        let mut len: usize = 0;
131        len += 4;
132        if version >= 1 {
133            len += 2;
134        } else if self.error_code != 0_i16 {
135            return Err(UnsupportedFieldVersion::new(43, "error_code", version).into());
136        }
137        if version >= 2 {
138            len += compact_array_length_len(self.replica_election_results.len() as i32);
139            for el in &self.replica_election_results {
140                len += el.encoded_len(version)?;
141            }
142        } else {
143            len += array_length_len();
144            for el in &self.replica_election_results {
145                len += el.encoded_len(version)?;
146            }
147        }
148        if version >= 2 {
149            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
150            all_tags.sort_by_key(|f| f.tag);
151            len += tagged_fields_len(&all_tags)?;
152        }
153        Ok(len)
154    }
155}
156#[derive(Debug, Clone, PartialEq)]
157pub struct ReplicaElectionResult {
158    /// The topic name.
159    pub topic: KafkaString,
160    /// The results for each partition.
161    pub partition_result: Vec<PartitionResult>,
162    pub _unknown_tagged_fields: Vec<RawTaggedField>,
163}
164impl Default for ReplicaElectionResult {
165    fn default() -> Self {
166        Self {
167            topic: KafkaString::default(),
168            partition_result: Vec::new(),
169            _unknown_tagged_fields: Vec::new(),
170        }
171    }
172}
173impl ReplicaElectionResult {
174    pub fn with_topic(mut self, value: KafkaString) -> Self {
175        self.topic = value;
176        self
177    }
178    pub fn with_partition_result(mut self, value: Vec<PartitionResult>) -> Self {
179        self.partition_result = value;
180        self
181    }
182    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
183        let topic;
184        let partition_result;
185        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
186        if version >= 2 {
187            topic = read_compact_string(buf)?;
188        } else {
189            topic = read_string(buf)?;
190        }
191        if version >= 2 {
192            partition_result = {
193                let len = read_compact_array_length(buf)?;
194                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
195                for _ in 0..len {
196                    arr.push(PartitionResult::read(buf, version)?);
197                }
198                arr
199            };
200        } else {
201            partition_result = {
202                let len = read_array_length(buf)?;
203                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
204                for _ in 0..len {
205                    arr.push(PartitionResult::read(buf, version)?);
206                }
207                arr
208            };
209        }
210        if version >= 2 {
211            let tagged_fields = read_tagged_fields(buf)?;
212            for field in &tagged_fields {
213                match field.tag {
214                    _ => {
215                        _unknown_tagged_fields.push(field.clone());
216                    },
217                }
218            }
219        }
220        Ok(Self {
221            topic,
222            partition_result,
223            _unknown_tagged_fields,
224        })
225    }
226    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
227        if version >= 2 {
228            write_compact_string(buf, &self.topic)?;
229        } else {
230            write_string(buf, &self.topic)?;
231        }
232        if version >= 2 {
233            write_compact_array_length(buf, self.partition_result.len() as i32);
234            for el in &self.partition_result {
235                el.write(buf, version)?;
236            }
237        } else {
238            write_array_length(buf, self.partition_result.len() as i32);
239            for el in &self.partition_result {
240                el.write(buf, version)?;
241            }
242        }
243        if version >= 2 {
244            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
245            all_tags.sort_by_key(|f| f.tag);
246            write_tagged_fields(buf, &all_tags)?;
247        }
248        Ok(())
249    }
250    pub fn encoded_len(&self, version: i16) -> Result<usize> {
251        let mut len: usize = 0;
252        if version >= 2 {
253            len += compact_string_len(&self.topic)?;
254        } else {
255            len += string_len(&self.topic)?;
256        }
257        if version >= 2 {
258            len += compact_array_length_len(self.partition_result.len() as i32);
259            for el in &self.partition_result {
260                len += el.encoded_len(version)?;
261            }
262        } else {
263            len += array_length_len();
264            for el in &self.partition_result {
265                len += el.encoded_len(version)?;
266            }
267        }
268        if version >= 2 {
269            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
270            all_tags.sort_by_key(|f| f.tag);
271            len += tagged_fields_len(&all_tags)?;
272        }
273        Ok(len)
274    }
275}
276#[derive(Debug, Clone, PartialEq)]
277pub struct PartitionResult {
278    /// The partition id.
279    pub partition_id: i32,
280    /// The result error, or zero if there was no error.
281    pub error_code: i16,
282    /// The result message, or null if there was no error.
283    pub error_message: Option<KafkaString>,
284    pub _unknown_tagged_fields: Vec<RawTaggedField>,
285}
286impl Default for PartitionResult {
287    fn default() -> Self {
288        Self {
289            partition_id: 0_i32,
290            error_code: 0_i16,
291            error_message: None,
292            _unknown_tagged_fields: Vec::new(),
293        }
294    }
295}
296impl PartitionResult {
297    pub fn with_partition_id(mut self, value: i32) -> Self {
298        self.partition_id = value;
299        self
300    }
301    pub fn with_error_code(mut self, value: i16) -> Self {
302        self.error_code = value;
303        self
304    }
305    pub fn with_error_message(mut self, value: Option<KafkaString>) -> Self {
306        self.error_message = value;
307        self
308    }
309    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
310        let partition_id;
311        let error_code;
312        let error_message;
313        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
314        partition_id = read_i32(buf)?;
315        error_code = read_i16(buf)?;
316        if version >= 2 {
317            error_message = read_compact_nullable_string(buf)?;
318        } else {
319            error_message = read_nullable_string(buf)?;
320        }
321        if version >= 2 {
322            let tagged_fields = read_tagged_fields(buf)?;
323            for field in &tagged_fields {
324                match field.tag {
325                    _ => {
326                        _unknown_tagged_fields.push(field.clone());
327                    },
328                }
329            }
330        }
331        Ok(Self {
332            partition_id,
333            error_code,
334            error_message,
335            _unknown_tagged_fields,
336        })
337    }
338    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
339        write_i32(buf, self.partition_id);
340        write_i16(buf, self.error_code);
341        if version >= 2 {
342            write_compact_nullable_string(buf, self.error_message.as_ref())?;
343        } else {
344            write_nullable_string(buf, self.error_message.as_ref())?;
345        }
346        if version >= 2 {
347            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
348            all_tags.sort_by_key(|f| f.tag);
349            write_tagged_fields(buf, &all_tags)?;
350        }
351        Ok(())
352    }
353    pub fn encoded_len(&self, version: i16) -> Result<usize> {
354        let mut len: usize = 0;
355        len += 4;
356        len += 2;
357        if version >= 2 {
358            len += compact_nullable_string_len(self.error_message.as_ref())?;
359        } else {
360            len += nullable_string_len(self.error_message.as_ref())?;
361        }
362        if version >= 2 {
363            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
364            all_tags.sort_by_key(|f| f.tag);
365            len += tagged_fields_len(&all_tags)?;
366        }
367        Ok(len)
368    }
369}