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 DescribeTopicPartitionsResponseData {
17 pub throttle_time_ms: i32,
20 pub topics: Vec<DescribeTopicPartitionsResponseTopic>,
22 pub next_cursor: Option<Box<Cursor>>,
24 pub _unknown_tagged_fields: Vec<RawTaggedField>,
25}
26impl Default for DescribeTopicPartitionsResponseData {
27 fn default() -> Self {
28 Self {
29 throttle_time_ms: 0_i32,
30 topics: Vec::new(),
31 next_cursor: None,
32 _unknown_tagged_fields: Vec::new(),
33 }
34 }
35}
36impl DescribeTopicPartitionsResponseData {
37 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
38 self.throttle_time_ms = value;
39 self
40 }
41 pub fn with_topics(mut self, value: Vec<DescribeTopicPartitionsResponseTopic>) -> Self {
42 self.topics = value;
43 self
44 }
45 pub fn with_next_cursor(mut self, value: Option<Box<Cursor>>) -> Self {
46 self.next_cursor = value;
47 self
48 }
49 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
50 if version < 0 || version > 0 {
51 return Err(UnsupportedVersion::new(75, version).into());
52 }
53 let throttle_time_ms;
54 let topics;
55 let next_cursor;
56 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
57 throttle_time_ms = read_i32(buf)?;
58 topics = {
59 let len = read_compact_array_length(buf)?;
60 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
61 for _ in 0..len {
62 arr.push(DescribeTopicPartitionsResponseTopic::read(buf, version)?);
63 }
64 arr
65 };
66 next_cursor = {
67 let marker = read_i8(buf)?;
68 if marker < 0 {
69 None
70 } else {
71 Some(Box::new(Cursor::read(buf, version)?))
72 }
73 };
74 let tagged_fields = read_tagged_fields(buf)?;
75 for field in &tagged_fields {
76 match field.tag {
77 _ => {
78 _unknown_tagged_fields.push(field.clone());
79 },
80 }
81 }
82 Ok(Self {
83 throttle_time_ms,
84 topics,
85 next_cursor,
86 _unknown_tagged_fields,
87 })
88 }
89 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
90 if version < 0 || version > 0 {
91 return Err(UnsupportedVersion::new(75, version).into());
92 }
93 write_i32(buf, self.throttle_time_ms);
94 write_compact_array_length(buf, self.topics.len() as i32);
95 for el in &self.topics {
96 el.write(buf, version)?;
97 }
98 match &self.next_cursor {
99 None => {
100 write_i8(buf, -1);
101 },
102 Some(v) => {
103 write_i8(buf, 1);
104 v.write(buf, version)?;
105 },
106 }
107 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
108 all_tags.sort_by_key(|f| f.tag);
109 write_tagged_fields(buf, &all_tags)?;
110 Ok(())
111 }
112 pub fn encoded_len(&self, version: i16) -> Result<usize> {
113 if version < 0 || version > 0 {
114 return Err(UnsupportedVersion::new(75, version).into());
115 }
116 let mut len: usize = 0;
117 len += 4;
118 len += compact_array_length_len(self.topics.len() as i32);
119 for el in &self.topics {
120 len += el.encoded_len(version)?;
121 }
122 match &self.next_cursor {
123 None => {
124 len += 1;
125 },
126 Some(v) => {
127 len += 1;
128 len += v.encoded_len(version)?;
129 },
130 }
131 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
132 all_tags.sort_by_key(|f| f.tag);
133 len += tagged_fields_len(&all_tags)?;
134 Ok(len)
135 }
136}
137#[derive(Debug, Clone, PartialEq)]
138pub struct DescribeTopicPartitionsResponseTopic {
139 pub error_code: i16,
141 pub name: Option<KafkaString>,
143 pub topic_id: KafkaUuid,
145 pub is_internal: bool,
147 pub partitions: Vec<DescribeTopicPartitionsResponsePartition>,
149 pub topic_authorized_operations: i32,
151 pub _unknown_tagged_fields: Vec<RawTaggedField>,
152}
153impl Default for DescribeTopicPartitionsResponseTopic {
154 fn default() -> Self {
155 Self {
156 error_code: 0_i16,
157 name: None,
158 topic_id: KafkaUuid::ZERO,
159 is_internal: false,
160 partitions: Vec::new(),
161 topic_authorized_operations: i32::MIN,
162 _unknown_tagged_fields: Vec::new(),
163 }
164 }
165}
166impl DescribeTopicPartitionsResponseTopic {
167 pub fn with_error_code(mut self, value: i16) -> Self {
168 self.error_code = value;
169 self
170 }
171 pub fn with_name(mut self, value: Option<KafkaString>) -> Self {
172 self.name = value;
173 self
174 }
175 pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
176 self.topic_id = value;
177 self
178 }
179 pub fn with_is_internal(mut self, value: bool) -> Self {
180 self.is_internal = value;
181 self
182 }
183 pub fn with_partitions(mut self, value: Vec<DescribeTopicPartitionsResponsePartition>) -> Self {
184 self.partitions = value;
185 self
186 }
187 pub fn with_topic_authorized_operations(mut self, value: i32) -> Self {
188 self.topic_authorized_operations = value;
189 self
190 }
191 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
192 let error_code;
193 let name;
194 let topic_id;
195 let is_internal;
196 let partitions;
197 let topic_authorized_operations;
198 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
199 error_code = read_i16(buf)?;
200 name = read_compact_nullable_string(buf)?;
201 topic_id = read_uuid(buf)?;
202 is_internal = read_bool(buf)?;
203 partitions = {
204 let len = read_compact_array_length(buf)?;
205 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
206 for _ in 0..len {
207 arr.push(DescribeTopicPartitionsResponsePartition::read(
208 buf, version,
209 )?);
210 }
211 arr
212 };
213 topic_authorized_operations = read_i32(buf)?;
214 let tagged_fields = read_tagged_fields(buf)?;
215 for field in &tagged_fields {
216 match field.tag {
217 _ => {
218 _unknown_tagged_fields.push(field.clone());
219 },
220 }
221 }
222 Ok(Self {
223 error_code,
224 name,
225 topic_id,
226 is_internal,
227 partitions,
228 topic_authorized_operations,
229 _unknown_tagged_fields,
230 })
231 }
232 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
233 write_i16(buf, self.error_code);
234 write_compact_nullable_string(buf, self.name.as_ref())?;
235 write_uuid(buf, &self.topic_id);
236 write_bool(buf, self.is_internal);
237 write_compact_array_length(buf, self.partitions.len() as i32);
238 for el in &self.partitions {
239 el.write(buf, version)?;
240 }
241 write_i32(buf, self.topic_authorized_operations);
242 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
243 all_tags.sort_by_key(|f| f.tag);
244 write_tagged_fields(buf, &all_tags)?;
245 Ok(())
246 }
247 pub fn encoded_len(&self, version: i16) -> Result<usize> {
248 let mut len: usize = 0;
249 len += 2;
250 len += compact_nullable_string_len(self.name.as_ref())?;
251 len += 16;
252 len += 1;
253 len += compact_array_length_len(self.partitions.len() as i32);
254 for el in &self.partitions {
255 len += el.encoded_len(version)?;
256 }
257 len += 4;
258 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
259 all_tags.sort_by_key(|f| f.tag);
260 len += tagged_fields_len(&all_tags)?;
261 Ok(len)
262 }
263}
264#[derive(Debug, Clone, PartialEq)]
265pub struct DescribeTopicPartitionsResponsePartition {
266 pub error_code: i16,
268 pub partition_index: i32,
270 pub leader_id: i32,
272 pub leader_epoch: i32,
274 pub replica_nodes: Vec<i32>,
276 pub isr_nodes: Vec<i32>,
278 pub eligible_leader_replicas: Option<Vec<i32>>,
280 pub last_known_elr: Option<Vec<i32>>,
282 pub offline_replicas: Vec<i32>,
284 pub _unknown_tagged_fields: Vec<RawTaggedField>,
285}
286impl Default for DescribeTopicPartitionsResponsePartition {
287 fn default() -> Self {
288 Self {
289 error_code: 0_i16,
290 partition_index: 0_i32,
291 leader_id: 0_i32,
292 leader_epoch: -1i32,
293 replica_nodes: Vec::new(),
294 isr_nodes: Vec::new(),
295 eligible_leader_replicas: None,
296 last_known_elr: None,
297 offline_replicas: Vec::new(),
298 _unknown_tagged_fields: Vec::new(),
299 }
300 }
301}
302impl DescribeTopicPartitionsResponsePartition {
303 pub fn with_error_code(mut self, value: i16) -> Self {
304 self.error_code = value;
305 self
306 }
307 pub fn with_partition_index(mut self, value: i32) -> Self {
308 self.partition_index = value;
309 self
310 }
311 pub fn with_leader_id(mut self, value: i32) -> Self {
312 self.leader_id = value;
313 self
314 }
315 pub fn with_leader_epoch(mut self, value: i32) -> Self {
316 self.leader_epoch = value;
317 self
318 }
319 pub fn with_replica_nodes(mut self, value: Vec<i32>) -> Self {
320 self.replica_nodes = value;
321 self
322 }
323 pub fn with_isr_nodes(mut self, value: Vec<i32>) -> Self {
324 self.isr_nodes = value;
325 self
326 }
327 pub fn with_eligible_leader_replicas(mut self, value: Option<Vec<i32>>) -> Self {
328 self.eligible_leader_replicas = value;
329 self
330 }
331 pub fn with_last_known_elr(mut self, value: Option<Vec<i32>>) -> Self {
332 self.last_known_elr = value;
333 self
334 }
335 pub fn with_offline_replicas(mut self, value: Vec<i32>) -> Self {
336 self.offline_replicas = value;
337 self
338 }
339 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
340 let error_code;
341 let partition_index;
342 let leader_id;
343 let leader_epoch;
344 let replica_nodes;
345 let isr_nodes;
346 let eligible_leader_replicas;
347 let last_known_elr;
348 let offline_replicas;
349 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
350 error_code = read_i16(buf)?;
351 partition_index = read_i32(buf)?;
352 leader_id = read_i32(buf)?;
353 leader_epoch = read_i32(buf)?;
354 replica_nodes = {
355 let len = read_compact_array_length(buf)?;
356 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
357 for _ in 0..len {
358 arr.push(read_i32(buf)?);
359 }
360 arr
361 };
362 isr_nodes = {
363 let len = read_compact_array_length(buf)?;
364 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
365 for _ in 0..len {
366 arr.push(read_i32(buf)?);
367 }
368 arr
369 };
370 eligible_leader_replicas = {
371 let len = read_compact_array_length(buf)?;
372 if len < 0 {
373 None
374 } else {
375 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
376 for _ in 0..len {
377 arr.push(read_i32(buf)?);
378 }
379 Some(arr)
380 }
381 };
382 last_known_elr = {
383 let len = read_compact_array_length(buf)?;
384 if len < 0 {
385 None
386 } else {
387 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
388 for _ in 0..len {
389 arr.push(read_i32(buf)?);
390 }
391 Some(arr)
392 }
393 };
394 offline_replicas = {
395 let len = read_compact_array_length(buf)?;
396 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
397 for _ in 0..len {
398 arr.push(read_i32(buf)?);
399 }
400 arr
401 };
402 let tagged_fields = read_tagged_fields(buf)?;
403 for field in &tagged_fields {
404 match field.tag {
405 _ => {
406 _unknown_tagged_fields.push(field.clone());
407 },
408 }
409 }
410 Ok(Self {
411 error_code,
412 partition_index,
413 leader_id,
414 leader_epoch,
415 replica_nodes,
416 isr_nodes,
417 eligible_leader_replicas,
418 last_known_elr,
419 offline_replicas,
420 _unknown_tagged_fields,
421 })
422 }
423 pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
424 write_i16(buf, self.error_code);
425 write_i32(buf, self.partition_index);
426 write_i32(buf, self.leader_id);
427 write_i32(buf, self.leader_epoch);
428 write_compact_array_length(buf, self.replica_nodes.len() as i32);
429 for el in &self.replica_nodes {
430 write_i32(buf, *el);
431 }
432 write_compact_array_length(buf, self.isr_nodes.len() as i32);
433 for el in &self.isr_nodes {
434 write_i32(buf, *el);
435 }
436 match &self.eligible_leader_replicas {
437 None => {
438 write_compact_array_length(buf, -1);
439 },
440 Some(arr) => {
441 write_compact_array_length(buf, arr.len() as i32);
442 for el in arr {
443 write_i32(buf, *el);
444 }
445 },
446 }
447 match &self.last_known_elr {
448 None => {
449 write_compact_array_length(buf, -1);
450 },
451 Some(arr) => {
452 write_compact_array_length(buf, arr.len() as i32);
453 for el in arr {
454 write_i32(buf, *el);
455 }
456 },
457 }
458 write_compact_array_length(buf, self.offline_replicas.len() as i32);
459 for el in &self.offline_replicas {
460 write_i32(buf, *el);
461 }
462 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
463 all_tags.sort_by_key(|f| f.tag);
464 write_tagged_fields(buf, &all_tags)?;
465 Ok(())
466 }
467 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
468 let mut len: usize = 0;
469 len += 2;
470 len += 4;
471 len += 4;
472 len += 4;
473 len += compact_array_length_len(self.replica_nodes.len() as i32);
474 len += self.replica_nodes.len() * 4usize;
475 len += compact_array_length_len(self.isr_nodes.len() as i32);
476 len += self.isr_nodes.len() * 4usize;
477 match &self.eligible_leader_replicas {
478 None => {
479 len += compact_array_length_len(-1);
480 },
481 Some(arr) => {
482 len += compact_array_length_len(arr.len() as i32);
483 len += arr.len() * 4usize;
484 },
485 }
486 match &self.last_known_elr {
487 None => {
488 len += compact_array_length_len(-1);
489 },
490 Some(arr) => {
491 len += compact_array_length_len(arr.len() as i32);
492 len += arr.len() * 4usize;
493 },
494 }
495 len += compact_array_length_len(self.offline_replicas.len() as i32);
496 len += self.offline_replicas.len() * 4usize;
497 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
498 all_tags.sort_by_key(|f| f.tag);
499 len += tagged_fields_len(&all_tags)?;
500 Ok(len)
501 }
502}
503#[derive(Debug, Clone, PartialEq)]
504pub struct Cursor {
505 pub topic_name: KafkaString,
507 pub partition_index: i32,
509 pub _unknown_tagged_fields: Vec<RawTaggedField>,
510}
511impl Default for Cursor {
512 fn default() -> Self {
513 Self {
514 topic_name: KafkaString::default(),
515 partition_index: 0_i32,
516 _unknown_tagged_fields: Vec::new(),
517 }
518 }
519}
520impl Cursor {
521 pub fn with_topic_name(mut self, value: KafkaString) -> Self {
522 self.topic_name = value;
523 self
524 }
525 pub fn with_partition_index(mut self, value: i32) -> Self {
526 self.partition_index = value;
527 self
528 }
529 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
530 let topic_name;
531 let partition_index;
532 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
533 topic_name = read_compact_string(buf)?;
534 partition_index = read_i32(buf)?;
535 let tagged_fields = read_tagged_fields(buf)?;
536 for field in &tagged_fields {
537 match field.tag {
538 _ => {
539 _unknown_tagged_fields.push(field.clone());
540 },
541 }
542 }
543 Ok(Self {
544 topic_name,
545 partition_index,
546 _unknown_tagged_fields,
547 })
548 }
549 pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
550 write_compact_string(buf, &self.topic_name)?;
551 write_i32(buf, self.partition_index);
552 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
553 all_tags.sort_by_key(|f| f.tag);
554 write_tagged_fields(buf, &all_tags)?;
555 Ok(())
556 }
557 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
558 let mut len: usize = 0;
559 len += compact_string_len(&self.topic_name)?;
560 len += 4;
561 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
562 all_tags.sort_by_key(|f| f.tag);
563 len += tagged_fields_len(&all_tags)?;
564 Ok(len)
565 }
566}