Skip to main content

kacrab_protocol/generated/
vote_response.rs

1//! Generated from VoteResponse.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 VoteResponseData {
17    /// The top level error code.
18    pub error_code: i16,
19    /// The results for each topic.
20    pub topics: Vec<TopicData>,
21    /// Endpoints for all current-leaders enumerated in PartitionData.
22    pub node_endpoints: Vec<NodeEndpoint>,
23    pub _unknown_tagged_fields: Vec<RawTaggedField>,
24}
25impl Default for VoteResponseData {
26    fn default() -> Self {
27        Self {
28            error_code: 0_i16,
29            topics: Vec::new(),
30            node_endpoints: Vec::new(),
31            _unknown_tagged_fields: Vec::new(),
32        }
33    }
34}
35impl VoteResponseData {
36    pub fn with_error_code(mut self, value: i16) -> Self {
37        self.error_code = value;
38        self
39    }
40    pub fn with_topics(mut self, value: Vec<TopicData>) -> Self {
41        self.topics = value;
42        self
43    }
44    pub fn with_node_endpoints(mut self, value: Vec<NodeEndpoint>) -> Self {
45        self.node_endpoints = value;
46        self
47    }
48    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
49        if version < 0 || version > 2 {
50            return Err(UnsupportedVersion::new(52, version).into());
51        }
52        let error_code;
53        let topics;
54        let mut node_endpoints = Vec::new();
55        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
56        error_code = read_i16(buf)?;
57        topics = {
58            let len = read_compact_array_length(buf)?;
59            let mut arr = Vec::with_capacity(len.max(0) as usize);
60            for _ in 0..len {
61                arr.push(TopicData::read(buf, version)?);
62            }
63            arr
64        };
65        let tagged_fields = read_tagged_fields(buf)?;
66        for field in &tagged_fields {
67            match field.tag {
68                0 => {
69                    if version >= 1 {
70                        let mut tag_buf = field.data.clone();
71                        node_endpoints = {
72                            let len = read_compact_array_length(&mut tag_buf)?;
73                            let mut arr = Vec::with_capacity(len.max(0) as usize);
74                            for _ in 0..len {
75                                arr.push(NodeEndpoint::read(&mut tag_buf, version)?);
76                            }
77                            arr
78                        };
79                    }
80                },
81                _ => {
82                    _unknown_tagged_fields.push(field.clone());
83                },
84            }
85        }
86        Ok(Self {
87            error_code,
88            topics,
89            node_endpoints,
90            _unknown_tagged_fields,
91        })
92    }
93    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
94        if version < 0 || version > 2 {
95            return Err(UnsupportedVersion::new(52, version).into());
96        }
97        write_i16(buf, self.error_code);
98        write_compact_array_length(buf, self.topics.len() as i32);
99        for el in &self.topics {
100            el.write(buf, version)?;
101        }
102        let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
103        if version >= 1 && !self.node_endpoints.is_empty() {
104            let mut tag_buf = BytesMut::new();
105            write_compact_array_length(&mut tag_buf, self.node_endpoints.len() as i32);
106            for el in &self.node_endpoints {
107                el.write(&mut tag_buf, version)?;
108            }
109            known_tagged_fields.push(RawTaggedField {
110                tag: 0,
111                data: tag_buf.freeze(),
112            });
113        }
114        let mut all_tags = known_tagged_fields;
115        all_tags.extend(self._unknown_tagged_fields.iter().cloned());
116        all_tags.sort_by_key(|f| f.tag);
117        write_tagged_fields(buf, &all_tags)?;
118        Ok(())
119    }
120    pub fn encoded_len(&self, version: i16) -> Result<usize> {
121        if version < 0 || version > 2 {
122            return Err(UnsupportedVersion::new(52, version).into());
123        }
124        let mut len: usize = 0;
125        len += 2;
126        len += compact_array_length_len(self.topics.len() as i32);
127        for el in &self.topics {
128            len += el.encoded_len(version)?;
129        }
130        let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
131        if version >= 1 && !self.node_endpoints.is_empty() {
132            let mut tag_buf = BytesMut::new();
133            write_compact_array_length(&mut tag_buf, self.node_endpoints.len() as i32);
134            for el in &self.node_endpoints {
135                el.write(&mut tag_buf, version)?;
136            }
137            known_tagged_fields.push(RawTaggedField {
138                tag: 0,
139                data: tag_buf.freeze(),
140            });
141        }
142        let mut all_tags = known_tagged_fields;
143        all_tags.extend(self._unknown_tagged_fields.iter().cloned());
144        all_tags.sort_by_key(|f| f.tag);
145        len += tagged_fields_len(&all_tags)?;
146        Ok(len)
147    }
148}
149#[derive(Debug, Clone, PartialEq)]
150pub struct TopicData {
151    /// The topic name.
152    pub topic_name: KafkaString,
153    /// The results for each partition.
154    pub partitions: Vec<PartitionData>,
155    pub _unknown_tagged_fields: Vec<RawTaggedField>,
156}
157impl Default for TopicData {
158    fn default() -> Self {
159        Self {
160            topic_name: KafkaString::default(),
161            partitions: Vec::new(),
162            _unknown_tagged_fields: Vec::new(),
163        }
164    }
165}
166impl TopicData {
167    pub fn with_topic_name(mut self, value: KafkaString) -> Self {
168        self.topic_name = value;
169        self
170    }
171    pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
172        self.partitions = value;
173        self
174    }
175    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
176        let topic_name;
177        let partitions;
178        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
179        topic_name = read_compact_string(buf)?;
180        partitions = {
181            let len = read_compact_array_length(buf)?;
182            let mut arr = Vec::with_capacity(len.max(0) as usize);
183            for _ in 0..len {
184                arr.push(PartitionData::read(buf, version)?);
185            }
186            arr
187        };
188        let tagged_fields = read_tagged_fields(buf)?;
189        for field in &tagged_fields {
190            match field.tag {
191                _ => {
192                    _unknown_tagged_fields.push(field.clone());
193                },
194            }
195        }
196        Ok(Self {
197            topic_name,
198            partitions,
199            _unknown_tagged_fields,
200        })
201    }
202    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
203        write_compact_string(buf, &self.topic_name)?;
204        write_compact_array_length(buf, self.partitions.len() as i32);
205        for el in &self.partitions {
206            el.write(buf, version)?;
207        }
208        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
209        all_tags.sort_by_key(|f| f.tag);
210        write_tagged_fields(buf, &all_tags)?;
211        Ok(())
212    }
213    pub fn encoded_len(&self, version: i16) -> Result<usize> {
214        let mut len: usize = 0;
215        len += compact_string_len(&self.topic_name)?;
216        len += compact_array_length_len(self.partitions.len() as i32);
217        for el in &self.partitions {
218            len += el.encoded_len(version)?;
219        }
220        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
221        all_tags.sort_by_key(|f| f.tag);
222        len += tagged_fields_len(&all_tags)?;
223        Ok(len)
224    }
225}
226#[derive(Debug, Clone, PartialEq)]
227pub struct PartitionData {
228    /// The partition index.
229    pub partition_index: i32,
230    /// The partition level error code.
231    pub error_code: i16,
232    /// The ID of the current leader or -1 if the leader is unknown.
233    pub leader_id: i32,
234    /// The latest known leader epoch.
235    pub leader_epoch: i32,
236    /// True if the vote was granted and false otherwise.
237    pub vote_granted: bool,
238    pub _unknown_tagged_fields: Vec<RawTaggedField>,
239}
240impl Default for PartitionData {
241    fn default() -> Self {
242        Self {
243            partition_index: 0_i32,
244            error_code: 0_i16,
245            leader_id: 0_i32,
246            leader_epoch: 0_i32,
247            vote_granted: false,
248            _unknown_tagged_fields: Vec::new(),
249        }
250    }
251}
252impl PartitionData {
253    pub fn with_partition_index(mut self, value: i32) -> Self {
254        self.partition_index = value;
255        self
256    }
257    pub fn with_error_code(mut self, value: i16) -> Self {
258        self.error_code = value;
259        self
260    }
261    pub fn with_leader_id(mut self, value: i32) -> Self {
262        self.leader_id = value;
263        self
264    }
265    pub fn with_leader_epoch(mut self, value: i32) -> Self {
266        self.leader_epoch = value;
267        self
268    }
269    pub fn with_vote_granted(mut self, value: bool) -> Self {
270        self.vote_granted = value;
271        self
272    }
273    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
274        let partition_index;
275        let error_code;
276        let leader_id;
277        let leader_epoch;
278        let vote_granted;
279        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
280        partition_index = read_i32(buf)?;
281        error_code = read_i16(buf)?;
282        leader_id = read_i32(buf)?;
283        leader_epoch = read_i32(buf)?;
284        vote_granted = read_bool(buf)?;
285        let tagged_fields = read_tagged_fields(buf)?;
286        for field in &tagged_fields {
287            match field.tag {
288                _ => {
289                    _unknown_tagged_fields.push(field.clone());
290                },
291            }
292        }
293        Ok(Self {
294            partition_index,
295            error_code,
296            leader_id,
297            leader_epoch,
298            vote_granted,
299            _unknown_tagged_fields,
300        })
301    }
302    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
303        write_i32(buf, self.partition_index);
304        write_i16(buf, self.error_code);
305        write_i32(buf, self.leader_id);
306        write_i32(buf, self.leader_epoch);
307        write_bool(buf, self.vote_granted);
308        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
309        all_tags.sort_by_key(|f| f.tag);
310        write_tagged_fields(buf, &all_tags)?;
311        Ok(())
312    }
313    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
314        let mut len: usize = 0;
315        len += 4;
316        len += 2;
317        len += 4;
318        len += 4;
319        len += 1;
320        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
321        all_tags.sort_by_key(|f| f.tag);
322        len += tagged_fields_len(&all_tags)?;
323        Ok(len)
324    }
325}
326#[derive(Debug, Clone, PartialEq)]
327pub struct NodeEndpoint {
328    /// The ID of the associated node.
329    pub node_id: i32,
330    /// The node's hostname.
331    pub host: KafkaString,
332    /// The node's port.
333    pub port: u16,
334    pub _unknown_tagged_fields: Vec<RawTaggedField>,
335}
336impl Default for NodeEndpoint {
337    fn default() -> Self {
338        Self {
339            node_id: 0_i32,
340            host: KafkaString::default(),
341            port: 0_u16,
342            _unknown_tagged_fields: Vec::new(),
343        }
344    }
345}
346impl NodeEndpoint {
347    pub fn with_node_id(mut self, value: i32) -> Self {
348        self.node_id = value;
349        self
350    }
351    pub fn with_host(mut self, value: KafkaString) -> Self {
352        self.host = value;
353        self
354    }
355    pub fn with_port(mut self, value: u16) -> Self {
356        self.port = value;
357        self
358    }
359    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
360        let node_id;
361        let host;
362        let port;
363        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
364        node_id = read_i32(buf)?;
365        host = read_compact_string(buf)?;
366        port = read_u16(buf)?;
367        let tagged_fields = read_tagged_fields(buf)?;
368        for field in &tagged_fields {
369            match field.tag {
370                _ => {
371                    _unknown_tagged_fields.push(field.clone());
372                },
373            }
374        }
375        Ok(Self {
376            node_id,
377            host,
378            port,
379            _unknown_tagged_fields,
380        })
381    }
382    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
383        write_i32(buf, self.node_id);
384        write_compact_string(buf, &self.host)?;
385        write_u16(buf, self.port);
386        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
387        all_tags.sort_by_key(|f| f.tag);
388        write_tagged_fields(buf, &all_tags)?;
389        Ok(())
390    }
391    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
392        let mut len: usize = 0;
393        len += 4;
394        len += compact_string_len(&self.host)?;
395        len += 2;
396        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
397        all_tags.sort_by_key(|f| f.tag);
398        len += tagged_fields_len(&all_tags)?;
399        Ok(len)
400    }
401}