Skip to main content

kacrab_protocol/generated/
voters_record.rs

1//! Generated from VotersRecord.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 VotersRecordData {
17    /// The version of the voters record.
18    pub version: i16,
19    /// The set of voters in the quorum for this epoch.
20    pub voters: Vec<Voter>,
21    pub _unknown_tagged_fields: Vec<RawTaggedField>,
22}
23impl Default for VotersRecordData {
24    fn default() -> Self {
25        Self {
26            version: 0_i16,
27            voters: Vec::new(),
28            _unknown_tagged_fields: Vec::new(),
29        }
30    }
31}
32impl VotersRecordData {
33    pub fn with_version(mut self, value: i16) -> Self {
34        self.version = value;
35        self
36    }
37    pub fn with_voters(mut self, value: Vec<Voter>) -> Self {
38        self.voters = value;
39        self
40    }
41    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
42        let version_;
43        let voters;
44        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
45        version_ = read_i16(buf)?;
46        voters = {
47            let len = read_compact_array_length(buf)?;
48            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
49            for _ in 0..len {
50                arr.push(Voter::read(buf, version)?);
51            }
52            arr
53        };
54        let tagged_fields = read_tagged_fields(buf)?;
55        for field in &tagged_fields {
56            match field.tag {
57                _ => {
58                    _unknown_tagged_fields.push(field.clone());
59                },
60            }
61        }
62        Ok(Self {
63            version: version_,
64            voters,
65            _unknown_tagged_fields,
66        })
67    }
68    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
69        write_i16(buf, self.version);
70        write_compact_array_length(buf, self.voters.len() as i32);
71        for el in &self.voters {
72            el.write(buf, version)?;
73        }
74        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
75        all_tags.sort_by_key(|f| f.tag);
76        write_tagged_fields(buf, &all_tags)?;
77        Ok(())
78    }
79    pub fn encoded_len(&self, version: i16) -> Result<usize> {
80        let mut len: usize = 0;
81        len += 2;
82        len += compact_array_length_len(self.voters.len() as i32);
83        for el in &self.voters {
84            len += el.encoded_len(version)?;
85        }
86        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
87        all_tags.sort_by_key(|f| f.tag);
88        len += tagged_fields_len(&all_tags)?;
89        Ok(len)
90    }
91}
92#[derive(Debug, Clone, PartialEq)]
93pub struct Voter {
94    /// The replica id of the voter in the topic partition.
95    pub voter_id: i32,
96    /// The directory id of the voter in the topic partition.
97    pub voter_directory_id: KafkaUuid,
98    /// The endpoint that can be used to communicate with the voter.
99    pub endpoints: Vec<Endpoint>,
100    /// The range of versions of the protocol that the replica supports.
101    pub k_raft_version_feature: KRaftVersionFeature,
102    pub _unknown_tagged_fields: Vec<RawTaggedField>,
103}
104impl Default for Voter {
105    fn default() -> Self {
106        Self {
107            voter_id: 0_i32,
108            voter_directory_id: KafkaUuid::ZERO,
109            endpoints: Vec::new(),
110            k_raft_version_feature: KRaftVersionFeature::default(),
111            _unknown_tagged_fields: Vec::new(),
112        }
113    }
114}
115impl Voter {
116    pub fn with_voter_id(mut self, value: i32) -> Self {
117        self.voter_id = value;
118        self
119    }
120    pub fn with_voter_directory_id(mut self, value: KafkaUuid) -> Self {
121        self.voter_directory_id = value;
122        self
123    }
124    pub fn with_endpoints(mut self, value: Vec<Endpoint>) -> Self {
125        self.endpoints = value;
126        self
127    }
128    pub fn with_k_raft_version_feature(mut self, value: KRaftVersionFeature) -> Self {
129        self.k_raft_version_feature = value;
130        self
131    }
132    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
133        let voter_id;
134        let voter_directory_id;
135        let endpoints;
136        let k_raft_version_feature;
137        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
138        voter_id = read_i32(buf)?;
139        voter_directory_id = read_uuid(buf)?;
140        endpoints = {
141            let len = read_compact_array_length(buf)?;
142            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
143            for _ in 0..len {
144                arr.push(Endpoint::read(buf, version)?);
145            }
146            arr
147        };
148        k_raft_version_feature = KRaftVersionFeature::read(buf, version)?;
149        let tagged_fields = read_tagged_fields(buf)?;
150        for field in &tagged_fields {
151            match field.tag {
152                _ => {
153                    _unknown_tagged_fields.push(field.clone());
154                },
155            }
156        }
157        Ok(Self {
158            voter_id,
159            voter_directory_id,
160            endpoints,
161            k_raft_version_feature,
162            _unknown_tagged_fields,
163        })
164    }
165    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
166        write_i32(buf, self.voter_id);
167        write_uuid(buf, &self.voter_directory_id);
168        write_compact_array_length(buf, self.endpoints.len() as i32);
169        for el in &self.endpoints {
170            el.write(buf, version)?;
171        }
172        self.k_raft_version_feature.write(buf, version)?;
173        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
174        all_tags.sort_by_key(|f| f.tag);
175        write_tagged_fields(buf, &all_tags)?;
176        Ok(())
177    }
178    pub fn encoded_len(&self, version: i16) -> Result<usize> {
179        let mut len: usize = 0;
180        len += 4;
181        len += 16;
182        len += compact_array_length_len(self.endpoints.len() as i32);
183        for el in &self.endpoints {
184            len += el.encoded_len(version)?;
185        }
186        len += self.k_raft_version_feature.encoded_len(version)?;
187        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
188        all_tags.sort_by_key(|f| f.tag);
189        len += tagged_fields_len(&all_tags)?;
190        Ok(len)
191    }
192}
193#[derive(Debug, Clone, PartialEq)]
194pub struct Endpoint {
195    /// The name of the endpoint.
196    pub name: KafkaString,
197    /// The hostname.
198    pub host: KafkaString,
199    /// The port.
200    pub port: u16,
201    pub _unknown_tagged_fields: Vec<RawTaggedField>,
202}
203impl Default for Endpoint {
204    fn default() -> Self {
205        Self {
206            name: KafkaString::default(),
207            host: KafkaString::default(),
208            port: 0_u16,
209            _unknown_tagged_fields: Vec::new(),
210        }
211    }
212}
213impl Endpoint {
214    pub fn with_name(mut self, value: KafkaString) -> Self {
215        self.name = value;
216        self
217    }
218    pub fn with_host(mut self, value: KafkaString) -> Self {
219        self.host = value;
220        self
221    }
222    pub fn with_port(mut self, value: u16) -> Self {
223        self.port = value;
224        self
225    }
226    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
227        let name;
228        let host;
229        let port;
230        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
231        name = read_compact_string(buf)?;
232        host = read_compact_string(buf)?;
233        port = read_u16(buf)?;
234        let tagged_fields = read_tagged_fields(buf)?;
235        for field in &tagged_fields {
236            match field.tag {
237                _ => {
238                    _unknown_tagged_fields.push(field.clone());
239                },
240            }
241        }
242        Ok(Self {
243            name,
244            host,
245            port,
246            _unknown_tagged_fields,
247        })
248    }
249    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
250        write_compact_string(buf, &self.name)?;
251        write_compact_string(buf, &self.host)?;
252        write_u16(buf, self.port);
253        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
254        all_tags.sort_by_key(|f| f.tag);
255        write_tagged_fields(buf, &all_tags)?;
256        Ok(())
257    }
258    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
259        let mut len: usize = 0;
260        len += compact_string_len(&self.name)?;
261        len += compact_string_len(&self.host)?;
262        len += 2;
263        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
264        all_tags.sort_by_key(|f| f.tag);
265        len += tagged_fields_len(&all_tags)?;
266        Ok(len)
267    }
268}
269#[derive(Debug, Clone, PartialEq)]
270pub struct KRaftVersionFeature {
271    /// The minimum supported KRaft protocol version.
272    pub min_supported_version: i16,
273    /// The maximum supported KRaft protocol version.
274    pub max_supported_version: i16,
275    pub _unknown_tagged_fields: Vec<RawTaggedField>,
276}
277impl Default for KRaftVersionFeature {
278    fn default() -> Self {
279        Self {
280            min_supported_version: 0_i16,
281            max_supported_version: 0_i16,
282            _unknown_tagged_fields: Vec::new(),
283        }
284    }
285}
286impl KRaftVersionFeature {
287    pub fn with_min_supported_version(mut self, value: i16) -> Self {
288        self.min_supported_version = value;
289        self
290    }
291    pub fn with_max_supported_version(mut self, value: i16) -> Self {
292        self.max_supported_version = value;
293        self
294    }
295    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
296        let min_supported_version;
297        let max_supported_version;
298        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
299        min_supported_version = read_i16(buf)?;
300        max_supported_version = read_i16(buf)?;
301        let tagged_fields = read_tagged_fields(buf)?;
302        for field in &tagged_fields {
303            match field.tag {
304                _ => {
305                    _unknown_tagged_fields.push(field.clone());
306                },
307            }
308        }
309        Ok(Self {
310            min_supported_version,
311            max_supported_version,
312            _unknown_tagged_fields,
313        })
314    }
315    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
316        write_i16(buf, self.min_supported_version);
317        write_i16(buf, self.max_supported_version);
318        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
319        all_tags.sort_by_key(|f| f.tag);
320        write_tagged_fields(buf, &all_tags)?;
321        Ok(())
322    }
323    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
324        let mut len: usize = 0;
325        len += 2;
326        len += 2;
327        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
328        all_tags.sort_by_key(|f| f.tag);
329        len += tagged_fields_len(&all_tags)?;
330        Ok(len)
331    }
332}