Skip to main content

kacrab_protocol/generated/
begin_quorum_epoch_response.rs

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