kacrab_protocol/generated/
vote_request.rs1#![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 VoteRequestData {
17 pub cluster_id: Option<KafkaString>,
19 pub voter_id: i32,
21 pub topics: Vec<TopicData>,
23 pub _unknown_tagged_fields: Vec<RawTaggedField>,
24}
25impl Default for VoteRequestData {
26 fn default() -> Self {
27 Self {
28 cluster_id: None,
29 voter_id: -1i32,
30 topics: Vec::new(),
31 _unknown_tagged_fields: Vec::new(),
32 }
33 }
34}
35impl VoteRequestData {
36 pub fn with_cluster_id(mut self, value: Option<KafkaString>) -> Self {
37 self.cluster_id = value;
38 self
39 }
40 pub fn with_voter_id(mut self, value: i32) -> Self {
41 self.voter_id = value;
42 self
43 }
44 pub fn with_topics(mut self, value: Vec<TopicData>) -> Self {
45 self.topics = 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 cluster_id;
53 let mut voter_id = -1i32;
54 let topics;
55 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
56 cluster_id = read_compact_nullable_string(buf)?;
57 if version >= 1 {
58 voter_id = read_i32(buf)?;
59 }
60 topics = {
61 let len = read_compact_array_length(buf)?;
62 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
63 for _ in 0..len {
64 arr.push(TopicData::read(buf, version)?);
65 }
66 arr
67 };
68 let tagged_fields = read_tagged_fields(buf)?;
69 for field in &tagged_fields {
70 match field.tag {
71 _ => {
72 _unknown_tagged_fields.push(field.clone());
73 },
74 }
75 }
76 Ok(Self {
77 cluster_id,
78 voter_id,
79 topics,
80 _unknown_tagged_fields,
81 })
82 }
83 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
84 if version < 0 || version > 2 {
85 return Err(UnsupportedVersion::new(52, version).into());
86 }
87 write_compact_nullable_string(buf, self.cluster_id.as_ref())?;
88 if version >= 1 {
89 write_i32(buf, self.voter_id);
90 } else if self.voter_id != -1i32 {
91 return Err(UnsupportedFieldVersion::new(52, "voter_id", version).into());
92 }
93 write_compact_array_length(buf, self.topics.len() as i32);
94 for el in &self.topics {
95 el.write(buf, version)?;
96 }
97 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
98 all_tags.sort_by_key(|f| f.tag);
99 write_tagged_fields(buf, &all_tags)?;
100 Ok(())
101 }
102 pub fn encoded_len(&self, version: i16) -> Result<usize> {
103 if version < 0 || version > 2 {
104 return Err(UnsupportedVersion::new(52, version).into());
105 }
106 let mut len: usize = 0;
107 len += compact_nullable_string_len(self.cluster_id.as_ref())?;
108 if version >= 1 {
109 len += 4;
110 } else if self.voter_id != -1i32 {
111 return Err(UnsupportedFieldVersion::new(52, "voter_id", version).into());
112 }
113 len += compact_array_length_len(self.topics.len() as i32);
114 for el in &self.topics {
115 len += el.encoded_len(version)?;
116 }
117 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
118 all_tags.sort_by_key(|f| f.tag);
119 len += tagged_fields_len(&all_tags)?;
120 Ok(len)
121 }
122}
123#[derive(Debug, Clone, PartialEq)]
124pub struct TopicData {
125 pub topic_name: KafkaString,
127 pub partitions: Vec<PartitionData>,
129 pub _unknown_tagged_fields: Vec<RawTaggedField>,
130}
131impl Default for TopicData {
132 fn default() -> Self {
133 Self {
134 topic_name: KafkaString::default(),
135 partitions: Vec::new(),
136 _unknown_tagged_fields: Vec::new(),
137 }
138 }
139}
140impl TopicData {
141 pub fn with_topic_name(mut self, value: KafkaString) -> Self {
142 self.topic_name = value;
143 self
144 }
145 pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
146 self.partitions = value;
147 self
148 }
149 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
150 let topic_name;
151 let partitions;
152 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
153 topic_name = read_compact_string(buf)?;
154 partitions = {
155 let len = read_compact_array_length(buf)?;
156 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
157 for _ in 0..len {
158 arr.push(PartitionData::read(buf, version)?);
159 }
160 arr
161 };
162 let tagged_fields = read_tagged_fields(buf)?;
163 for field in &tagged_fields {
164 match field.tag {
165 _ => {
166 _unknown_tagged_fields.push(field.clone());
167 },
168 }
169 }
170 Ok(Self {
171 topic_name,
172 partitions,
173 _unknown_tagged_fields,
174 })
175 }
176 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
177 write_compact_string(buf, &self.topic_name)?;
178 write_compact_array_length(buf, self.partitions.len() as i32);
179 for el in &self.partitions {
180 el.write(buf, version)?;
181 }
182 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
183 all_tags.sort_by_key(|f| f.tag);
184 write_tagged_fields(buf, &all_tags)?;
185 Ok(())
186 }
187 pub fn encoded_len(&self, version: i16) -> Result<usize> {
188 let mut len: usize = 0;
189 len += compact_string_len(&self.topic_name)?;
190 len += compact_array_length_len(self.partitions.len() as i32);
191 for el in &self.partitions {
192 len += el.encoded_len(version)?;
193 }
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 Ok(len)
198 }
199}
200#[derive(Debug, Clone, PartialEq)]
201pub struct PartitionData {
202 pub partition_index: i32,
204 pub replica_epoch: i32,
206 pub replica_id: i32,
208 pub replica_directory_id: KafkaUuid,
210 pub voter_directory_id: KafkaUuid,
212 pub last_offset_epoch: i32,
214 pub last_offset: i64,
216 pub pre_vote: bool,
218 pub _unknown_tagged_fields: Vec<RawTaggedField>,
219}
220impl Default for PartitionData {
221 fn default() -> Self {
222 Self {
223 partition_index: 0_i32,
224 replica_epoch: 0_i32,
225 replica_id: 0_i32,
226 replica_directory_id: KafkaUuid::ZERO,
227 voter_directory_id: KafkaUuid::ZERO,
228 last_offset_epoch: 0_i32,
229 last_offset: 0_i64,
230 pre_vote: false,
231 _unknown_tagged_fields: Vec::new(),
232 }
233 }
234}
235impl PartitionData {
236 pub fn with_partition_index(mut self, value: i32) -> Self {
237 self.partition_index = value;
238 self
239 }
240 pub fn with_replica_epoch(mut self, value: i32) -> Self {
241 self.replica_epoch = value;
242 self
243 }
244 pub fn with_replica_id(mut self, value: i32) -> Self {
245 self.replica_id = value;
246 self
247 }
248 pub fn with_replica_directory_id(mut self, value: KafkaUuid) -> Self {
249 self.replica_directory_id = value;
250 self
251 }
252 pub fn with_voter_directory_id(mut self, value: KafkaUuid) -> Self {
253 self.voter_directory_id = value;
254 self
255 }
256 pub fn with_last_offset_epoch(mut self, value: i32) -> Self {
257 self.last_offset_epoch = value;
258 self
259 }
260 pub fn with_last_offset(mut self, value: i64) -> Self {
261 self.last_offset = value;
262 self
263 }
264 pub fn with_pre_vote(mut self, value: bool) -> Self {
265 self.pre_vote = value;
266 self
267 }
268 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
269 let partition_index;
270 let replica_epoch;
271 let replica_id;
272 let mut replica_directory_id = KafkaUuid::ZERO;
273 let mut voter_directory_id = KafkaUuid::ZERO;
274 let last_offset_epoch;
275 let last_offset;
276 let mut pre_vote = false;
277 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
278 partition_index = read_i32(buf)?;
279 replica_epoch = read_i32(buf)?;
280 replica_id = read_i32(buf)?;
281 if version >= 1 {
282 replica_directory_id = read_uuid(buf)?;
283 }
284 if version >= 1 {
285 voter_directory_id = read_uuid(buf)?;
286 }
287 last_offset_epoch = read_i32(buf)?;
288 last_offset = read_i64(buf)?;
289 if version >= 2 {
290 pre_vote = read_bool(buf)?;
291 }
292 let tagged_fields = read_tagged_fields(buf)?;
293 for field in &tagged_fields {
294 match field.tag {
295 _ => {
296 _unknown_tagged_fields.push(field.clone());
297 },
298 }
299 }
300 Ok(Self {
301 partition_index,
302 replica_epoch,
303 replica_id,
304 replica_directory_id,
305 voter_directory_id,
306 last_offset_epoch,
307 last_offset,
308 pre_vote,
309 _unknown_tagged_fields,
310 })
311 }
312 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
313 write_i32(buf, self.partition_index);
314 write_i32(buf, self.replica_epoch);
315 write_i32(buf, self.replica_id);
316 if version >= 1 {
317 write_uuid(buf, &self.replica_directory_id);
318 } else if self.replica_directory_id != KafkaUuid::ZERO {
319 return Err(UnsupportedFieldVersion::new(52, "replica_directory_id", version).into());
320 }
321 if version >= 1 {
322 write_uuid(buf, &self.voter_directory_id);
323 } else if self.voter_directory_id != KafkaUuid::ZERO {
324 return Err(UnsupportedFieldVersion::new(52, "voter_directory_id", version).into());
325 }
326 write_i32(buf, self.last_offset_epoch);
327 write_i64(buf, self.last_offset);
328 if version >= 2 {
329 write_bool(buf, self.pre_vote);
330 } else if self.pre_vote != false {
331 return Err(UnsupportedFieldVersion::new(52, "pre_vote", version).into());
332 }
333 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
334 all_tags.sort_by_key(|f| f.tag);
335 write_tagged_fields(buf, &all_tags)?;
336 Ok(())
337 }
338 pub fn encoded_len(&self, version: i16) -> Result<usize> {
339 let mut len: usize = 0;
340 len += 4;
341 len += 4;
342 len += 4;
343 if version >= 1 {
344 len += 16;
345 } else if self.replica_directory_id != KafkaUuid::ZERO {
346 return Err(UnsupportedFieldVersion::new(52, "replica_directory_id", version).into());
347 }
348 if version >= 1 {
349 len += 16;
350 } else if self.voter_directory_id != KafkaUuid::ZERO {
351 return Err(UnsupportedFieldVersion::new(52, "voter_directory_id", version).into());
352 }
353 len += 4;
354 len += 8;
355 if version >= 2 {
356 len += 1;
357 } else if self.pre_vote != false {
358 return Err(UnsupportedFieldVersion::new(52, "pre_vote", version).into());
359 }
360 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
361 all_tags.sort_by_key(|f| f.tag);
362 len += tagged_fields_len(&all_tags)?;
363 Ok(len)
364 }
365}