Skip to main content

kacrab_protocol/generated/
begin_quorum_epoch_request.rs

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