1#![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 EndQuorumEpochRequestData {
17 pub cluster_id: Option<KafkaString>,
19 pub topics: Vec<TopicData>,
21 pub leader_endpoints: Vec<LeaderEndpoint>,
23 pub _unknown_tagged_fields: Vec<RawTaggedField>,
24}
25impl Default for EndQuorumEpochRequestData {
26 fn default() -> Self {
27 Self {
28 cluster_id: None,
29 topics: Vec::new(),
30 leader_endpoints: Vec::new(),
31 _unknown_tagged_fields: Vec::new(),
32 }
33 }
34}
35impl EndQuorumEpochRequestData {
36 pub fn with_cluster_id(mut self, value: Option<KafkaString>) -> Self {
37 self.cluster_id = 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_leader_endpoints(mut self, value: Vec<LeaderEndpoint>) -> Self {
45 self.leader_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(54, version).into());
51 }
52 let cluster_id;
53 let topics;
54 let mut leader_endpoints = Vec::new();
55 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
56 if version >= 1 {
57 cluster_id = read_compact_nullable_string(buf)?;
58 } else {
59 cluster_id = read_nullable_string(buf)?;
60 }
61 if version >= 1 {
62 topics = {
63 let len = read_compact_array_length(buf)?;
64 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
65 for _ in 0..len {
66 arr.push(TopicData::read(buf, version)?);
67 }
68 arr
69 };
70 } else {
71 topics = {
72 let len = read_array_length(buf)?;
73 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
74 for _ in 0..len {
75 arr.push(TopicData::read(buf, version)?);
76 }
77 arr
78 };
79 }
80 if version >= 1 {
81 leader_endpoints = {
82 let len = read_compact_array_length(buf)?;
83 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
84 for _ in 0..len {
85 arr.push(LeaderEndpoint::read(buf, version)?);
86 }
87 arr
88 };
89 }
90 if version >= 1 {
91 let tagged_fields = read_tagged_fields(buf)?;
92 for field in &tagged_fields {
93 match field.tag {
94 _ => {
95 _unknown_tagged_fields.push(field.clone());
96 },
97 }
98 }
99 }
100 Ok(Self {
101 cluster_id,
102 topics,
103 leader_endpoints,
104 _unknown_tagged_fields,
105 })
106 }
107 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
108 if version < 0 || version > 1 {
109 return Err(UnsupportedVersion::new(54, version).into());
110 }
111 if version >= 1 {
112 write_compact_nullable_string(buf, self.cluster_id.as_ref())?;
113 } else {
114 write_nullable_string(buf, self.cluster_id.as_ref())?;
115 }
116 if version >= 1 {
117 write_compact_array_length(buf, self.topics.len() as i32);
118 for el in &self.topics {
119 el.write(buf, version)?;
120 }
121 } else {
122 write_array_length(buf, self.topics.len() as i32);
123 for el in &self.topics {
124 el.write(buf, version)?;
125 }
126 }
127 if version >= 1 {
128 write_compact_array_length(buf, self.leader_endpoints.len() as i32);
129 for el in &self.leader_endpoints {
130 el.write(buf, version)?;
131 }
132 } else if self.leader_endpoints != Vec::new() {
133 return Err(UnsupportedFieldVersion::new(54, "leader_endpoints", version).into());
134 }
135 if version >= 1 {
136 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
137 all_tags.sort_by_key(|f| f.tag);
138 write_tagged_fields(buf, &all_tags)?;
139 }
140 Ok(())
141 }
142 pub fn encoded_len(&self, version: i16) -> Result<usize> {
143 if version < 0 || version > 1 {
144 return Err(UnsupportedVersion::new(54, version).into());
145 }
146 let mut len: usize = 0;
147 if version >= 1 {
148 len += compact_nullable_string_len(self.cluster_id.as_ref())?;
149 } else {
150 len += nullable_string_len(self.cluster_id.as_ref())?;
151 }
152 if version >= 1 {
153 len += compact_array_length_len(self.topics.len() as i32);
154 for el in &self.topics {
155 len += el.encoded_len(version)?;
156 }
157 } else {
158 len += array_length_len();
159 for el in &self.topics {
160 len += el.encoded_len(version)?;
161 }
162 }
163 if version >= 1 {
164 len += compact_array_length_len(self.leader_endpoints.len() as i32);
165 for el in &self.leader_endpoints {
166 len += el.encoded_len(version)?;
167 }
168 } else if self.leader_endpoints != Vec::new() {
169 return Err(UnsupportedFieldVersion::new(54, "leader_endpoints", version).into());
170 }
171 if version >= 1 {
172 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
173 all_tags.sort_by_key(|f| f.tag);
174 len += tagged_fields_len(&all_tags)?;
175 }
176 Ok(len)
177 }
178}
179#[derive(Debug, Clone, PartialEq)]
180pub struct TopicData {
181 pub topic_name: KafkaString,
183 pub partitions: Vec<PartitionData>,
185 pub _unknown_tagged_fields: Vec<RawTaggedField>,
186}
187impl Default for TopicData {
188 fn default() -> Self {
189 Self {
190 topic_name: KafkaString::default(),
191 partitions: Vec::new(),
192 _unknown_tagged_fields: Vec::new(),
193 }
194 }
195}
196impl TopicData {
197 pub fn with_topic_name(mut self, value: KafkaString) -> Self {
198 self.topic_name = value;
199 self
200 }
201 pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
202 self.partitions = value;
203 self
204 }
205 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
206 let topic_name;
207 let partitions;
208 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
209 if version >= 1 {
210 topic_name = read_compact_string(buf)?;
211 } else {
212 topic_name = read_string(buf)?;
213 }
214 if version >= 1 {
215 partitions = {
216 let len = read_compact_array_length(buf)?;
217 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
218 for _ in 0..len {
219 arr.push(PartitionData::read(buf, version)?);
220 }
221 arr
222 };
223 } else {
224 partitions = {
225 let len = read_array_length(buf)?;
226 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
227 for _ in 0..len {
228 arr.push(PartitionData::read(buf, version)?);
229 }
230 arr
231 };
232 }
233 if version >= 1 {
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 }
243 Ok(Self {
244 topic_name,
245 partitions,
246 _unknown_tagged_fields,
247 })
248 }
249 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
250 if version >= 1 {
251 write_compact_string(buf, &self.topic_name)?;
252 } else {
253 write_string(buf, &self.topic_name)?;
254 }
255 if version >= 1 {
256 write_compact_array_length(buf, self.partitions.len() as i32);
257 for el in &self.partitions {
258 el.write(buf, version)?;
259 }
260 } else {
261 write_array_length(buf, self.partitions.len() as i32);
262 for el in &self.partitions {
263 el.write(buf, version)?;
264 }
265 }
266 if version >= 1 {
267 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
268 all_tags.sort_by_key(|f| f.tag);
269 write_tagged_fields(buf, &all_tags)?;
270 }
271 Ok(())
272 }
273 pub fn encoded_len(&self, version: i16) -> Result<usize> {
274 let mut len: usize = 0;
275 if version >= 1 {
276 len += compact_string_len(&self.topic_name)?;
277 } else {
278 len += string_len(&self.topic_name)?;
279 }
280 if version >= 1 {
281 len += compact_array_length_len(self.partitions.len() as i32);
282 for el in &self.partitions {
283 len += el.encoded_len(version)?;
284 }
285 } else {
286 len += array_length_len();
287 for el in &self.partitions {
288 len += el.encoded_len(version)?;
289 }
290 }
291 if version >= 1 {
292 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
293 all_tags.sort_by_key(|f| f.tag);
294 len += tagged_fields_len(&all_tags)?;
295 }
296 Ok(len)
297 }
298}
299#[derive(Debug, Clone, PartialEq)]
300pub struct PartitionData {
301 pub partition_index: i32,
303 pub leader_id: i32,
305 pub leader_epoch: i32,
307 pub preferred_successors: Vec<i32>,
309 pub preferred_candidates: Vec<ReplicaInfo>,
311 pub _unknown_tagged_fields: Vec<RawTaggedField>,
312}
313impl Default for PartitionData {
314 fn default() -> Self {
315 Self {
316 partition_index: 0_i32,
317 leader_id: 0_i32,
318 leader_epoch: 0_i32,
319 preferred_successors: Vec::new(),
320 preferred_candidates: Vec::new(),
321 _unknown_tagged_fields: Vec::new(),
322 }
323 }
324}
325impl PartitionData {
326 pub fn with_partition_index(mut self, value: i32) -> Self {
327 self.partition_index = 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 with_preferred_successors(mut self, value: Vec<i32>) -> Self {
339 self.preferred_successors = value;
340 self
341 }
342 pub fn with_preferred_candidates(mut self, value: Vec<ReplicaInfo>) -> Self {
343 self.preferred_candidates = value;
344 self
345 }
346 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
347 let partition_index;
348 let leader_id;
349 let leader_epoch;
350 let mut preferred_successors = Vec::new();
351 let mut preferred_candidates = Vec::new();
352 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
353 partition_index = read_i32(buf)?;
354 leader_id = read_i32(buf)?;
355 leader_epoch = read_i32(buf)?;
356 if version == 0 {
357 preferred_successors = {
358 let len = read_array_length(buf)?;
359 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
360 for _ in 0..len {
361 arr.push(read_i32(buf)?);
362 }
363 arr
364 };
365 }
366 if version >= 1 {
367 preferred_candidates = {
368 let len = read_compact_array_length(buf)?;
369 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
370 for _ in 0..len {
371 arr.push(ReplicaInfo::read(buf, version)?);
372 }
373 arr
374 };
375 }
376 if version >= 1 {
377 let tagged_fields = read_tagged_fields(buf)?;
378 for field in &tagged_fields {
379 match field.tag {
380 _ => {
381 _unknown_tagged_fields.push(field.clone());
382 },
383 }
384 }
385 }
386 Ok(Self {
387 partition_index,
388 leader_id,
389 leader_epoch,
390 preferred_successors,
391 preferred_candidates,
392 _unknown_tagged_fields,
393 })
394 }
395 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
396 write_i32(buf, self.partition_index);
397 write_i32(buf, self.leader_id);
398 write_i32(buf, self.leader_epoch);
399 if version == 0 {
400 write_array_length(buf, self.preferred_successors.len() as i32);
401 for el in &self.preferred_successors {
402 write_i32(buf, *el);
403 }
404 } else if self.preferred_successors != Vec::new() {
405 return Err(UnsupportedFieldVersion::new(54, "preferred_successors", version).into());
406 }
407 if version >= 1 {
408 write_compact_array_length(buf, self.preferred_candidates.len() as i32);
409 for el in &self.preferred_candidates {
410 el.write(buf, version)?;
411 }
412 } else if self.preferred_candidates != Vec::new() {
413 return Err(UnsupportedFieldVersion::new(54, "preferred_candidates", version).into());
414 }
415 if version >= 1 {
416 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
417 all_tags.sort_by_key(|f| f.tag);
418 write_tagged_fields(buf, &all_tags)?;
419 }
420 Ok(())
421 }
422 pub fn encoded_len(&self, version: i16) -> Result<usize> {
423 let mut len: usize = 0;
424 len += 4;
425 len += 4;
426 len += 4;
427 if version == 0 {
428 len += array_length_len();
429 len += self.preferred_successors.len() * 4usize;
430 } else if self.preferred_successors != Vec::new() {
431 return Err(UnsupportedFieldVersion::new(54, "preferred_successors", version).into());
432 }
433 if version >= 1 {
434 len += compact_array_length_len(self.preferred_candidates.len() as i32);
435 for el in &self.preferred_candidates {
436 len += el.encoded_len(version)?;
437 }
438 } else if self.preferred_candidates != Vec::new() {
439 return Err(UnsupportedFieldVersion::new(54, "preferred_candidates", version).into());
440 }
441 if version >= 1 {
442 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
443 all_tags.sort_by_key(|f| f.tag);
444 len += tagged_fields_len(&all_tags)?;
445 }
446 Ok(len)
447 }
448}
449#[derive(Debug, Clone, PartialEq)]
450pub struct ReplicaInfo {
451 pub candidate_id: i32,
453 pub candidate_directory_id: KafkaUuid,
455 pub _unknown_tagged_fields: Vec<RawTaggedField>,
456}
457impl Default for ReplicaInfo {
458 fn default() -> Self {
459 Self {
460 candidate_id: 0_i32,
461 candidate_directory_id: KafkaUuid::ZERO,
462 _unknown_tagged_fields: Vec::new(),
463 }
464 }
465}
466impl ReplicaInfo {
467 pub fn with_candidate_id(mut self, value: i32) -> Self {
468 self.candidate_id = value;
469 self
470 }
471 pub fn with_candidate_directory_id(mut self, value: KafkaUuid) -> Self {
472 self.candidate_directory_id = value;
473 self
474 }
475 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
476 let candidate_id;
477 let candidate_directory_id;
478 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
479 candidate_id = read_i32(buf)?;
480 candidate_directory_id = read_uuid(buf)?;
481 let tagged_fields = read_tagged_fields(buf)?;
482 for field in &tagged_fields {
483 match field.tag {
484 _ => {
485 _unknown_tagged_fields.push(field.clone());
486 },
487 }
488 }
489 Ok(Self {
490 candidate_id,
491 candidate_directory_id,
492 _unknown_tagged_fields,
493 })
494 }
495 pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
496 write_i32(buf, self.candidate_id);
497 write_uuid(buf, &self.candidate_directory_id);
498 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
499 all_tags.sort_by_key(|f| f.tag);
500 write_tagged_fields(buf, &all_tags)?;
501 Ok(())
502 }
503 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
504 let mut len: usize = 0;
505 len += 4;
506 len += 16;
507 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
508 all_tags.sort_by_key(|f| f.tag);
509 len += tagged_fields_len(&all_tags)?;
510 Ok(len)
511 }
512}
513#[derive(Debug, Clone, PartialEq)]
514pub struct LeaderEndpoint {
515 pub name: KafkaString,
517 pub host: KafkaString,
519 pub port: u16,
521 pub _unknown_tagged_fields: Vec<RawTaggedField>,
522}
523impl Default for LeaderEndpoint {
524 fn default() -> Self {
525 Self {
526 name: KafkaString::default(),
527 host: KafkaString::default(),
528 port: 0_u16,
529 _unknown_tagged_fields: Vec::new(),
530 }
531 }
532}
533impl LeaderEndpoint {
534 pub fn with_name(mut self, value: KafkaString) -> Self {
535 self.name = value;
536 self
537 }
538 pub fn with_host(mut self, value: KafkaString) -> Self {
539 self.host = value;
540 self
541 }
542 pub fn with_port(mut self, value: u16) -> Self {
543 self.port = value;
544 self
545 }
546 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
547 let name;
548 let host;
549 let port;
550 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
551 name = read_compact_string(buf)?;
552 host = read_compact_string(buf)?;
553 port = read_u16(buf)?;
554 let tagged_fields = read_tagged_fields(buf)?;
555 for field in &tagged_fields {
556 match field.tag {
557 _ => {
558 _unknown_tagged_fields.push(field.clone());
559 },
560 }
561 }
562 Ok(Self {
563 name,
564 host,
565 port,
566 _unknown_tagged_fields,
567 })
568 }
569 pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
570 write_compact_string(buf, &self.name)?;
571 write_compact_string(buf, &self.host)?;
572 write_u16(buf, self.port);
573 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
574 all_tags.sort_by_key(|f| f.tag);
575 write_tagged_fields(buf, &all_tags)?;
576 Ok(())
577 }
578 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
579 let mut len: usize = 0;
580 len += compact_string_len(&self.name)?;
581 len += compact_string_len(&self.host)?;
582 len += 2;
583 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
584 all_tags.sort_by_key(|f| f.tag);
585 len += tagged_fields_len(&all_tags)?;
586 Ok(len)
587 }
588}