1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 owned::describe_topic_partitions_response,
7 primitives::{
8 array::{
9 array_len_prefix_len, get_array_len, get_nullable_array_len,
10 nullable_array_len_prefix_len, put_array_len, put_nullable_array_len,
11 },
12 fixed::{get_bool, get_i8, get_i16, get_i32, put_bool, put_i16, put_i32},
13 string_bytes::{
14 compact_nullable_string_len, compact_string_len, nullable_string_len,
15 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
16 string_len,
17 },
18 string_bytes_borrowed::{
19 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
20 get_nullable_string_borrowed, get_string_borrowed,
21 },
22 uuid::{Uuid, get_uuid, put_uuid},
23 },
24 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
25};
26pub const API_KEY: i16 = 75;
27pub const MIN_VERSION: i16 = 0;
28pub const MAX_VERSION: i16 = 0;
29pub const FLEXIBLE_MIN: i16 = 0;
30#[inline]
31#[must_use]
32pub fn is_flexible(version: i16) -> bool {
33 version >= FLEXIBLE_MIN
34}
35#[derive(Debug, Clone, PartialEq, Eq, Default)]
36pub struct DescribeTopicPartitionsResponse<'a> {
37 pub throttle_time_ms: i32,
38 pub topics: Vec<DescribeTopicPartitionsResponseTopic<'a>>,
39 pub next_cursor: Option<Cursor<'a>>,
40 pub unknown_tagged_fields: UnknownTaggedFields,
41}
42impl DescribeTopicPartitionsResponse<'_> {
43 #[must_use]
44 pub fn to_owned(&self) -> describe_topic_partitions_response::DescribeTopicPartitionsResponse {
45 describe_topic_partitions_response::DescribeTopicPartitionsResponse {
46 throttle_time_ms: (self.throttle_time_ms),
47 topics: (self.topics)
48 .iter()
49 .map(DescribeTopicPartitionsResponseTopic::to_owned)
50 .collect(),
51 next_cursor: (self.next_cursor).as_ref().map(Cursor::to_owned),
52 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
53 }
54 }
55}
56impl Encode for DescribeTopicPartitionsResponse<'_> {
57 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
58 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
59 return Err(ProtocolError::UnsupportedVersion {
60 api_key: API_KEY,
61 version,
62 });
63 }
64 let flex = is_flexible(version);
65 if version >= 0 {
66 put_i32(buf, self.throttle_time_ms);
67 }
68 if version >= 0 {
69 {
70 put_array_len(buf, (self.topics).len(), flex)?;
71 for it in &self.topics {
72 it.encode(buf, version)?;
73 }
74 }
75 }
76 if version >= 0 {
77 match &self.next_cursor {
78 None => {
79 buf.put_i8(-1);
80 }
81 Some(v) => {
82 buf.put_i8(1);
83 v.encode(buf, version)?;
84 }
85 }
86 }
87 if flex {
88 let tagged = WriteTaggedFields::new();
89 tagged.write(buf, &self.unknown_tagged_fields)?;
90 }
91 Ok(())
92 }
93 fn encoded_len(&self, version: i16) -> usize {
94 let flex = is_flexible(version);
95 let mut n: usize = 0;
96 if version >= 0 {
97 n += 4;
98 }
99 if version >= 0 {
100 n += {
101 let prefix = array_len_prefix_len((self.topics).len(), flex);
102 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
103 prefix + body
104 };
105 }
106 if version >= 0 {
107 n += 1 + self
108 .next_cursor
109 .as_ref()
110 .map_or(0, |v| v.encoded_len(version));
111 }
112 if flex {
113 let known_pairs: Vec<(u32, usize)> = Vec::new();
114 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
115 }
116 n
117 }
118}
119impl<'de> DecodeBorrow<'de> for DescribeTopicPartitionsResponse<'de> {
120 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
121 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
122 return Err(ProtocolError::UnsupportedVersion {
123 api_key: API_KEY,
124 version,
125 });
126 }
127 let flex = is_flexible(version);
128 let mut out = Self::default();
129 if version >= 0 {
130 out.throttle_time_ms = get_i32(buf)?;
131 }
132 if version >= 0 {
133 out.topics = {
134 let n = get_array_len(buf, flex)?;
135 let mut v = Vec::with_capacity(n);
136 for _ in 0..n {
137 v.push(DescribeTopicPartitionsResponseTopic::decode_borrow(
138 buf, version,
139 )?);
140 }
141 v
142 };
143 }
144 if version >= 0 {
145 out.next_cursor = if get_i8(buf)? < 0 {
146 None
147 } else {
148 Some(Cursor::decode_borrow(buf, version)?)
149 };
150 }
151 if flex {
152 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
153 }
154 Ok(out)
155 }
156}
157#[cfg(test)]
158impl DescribeTopicPartitionsResponse<'_> {
159 #[must_use]
160 pub fn populated(version: i16) -> Self {
161 let mut m = Self::default();
162 if version >= 0 {
163 m.throttle_time_ms = 1i32;
164 }
165 if version >= 0 {
166 m.topics = vec![DescribeTopicPartitionsResponseTopic::populated(version)];
167 }
168 if version >= 0 {
169 m.next_cursor = Some(Cursor::populated(version));
170 }
171 m
172 }
173}
174#[derive(Debug, Clone, PartialEq, Eq)]
175pub struct DescribeTopicPartitionsResponseTopic<'a> {
176 pub error_code: i16,
177 pub name: Option<&'a str>,
178 pub topic_id: Uuid,
179 pub is_internal: bool,
180 pub partitions: Vec<DescribeTopicPartitionsResponsePartition>,
181 pub topic_authorized_operations: i32,
182 pub unknown_tagged_fields: UnknownTaggedFields,
183}
184impl Default for DescribeTopicPartitionsResponseTopic<'_> {
185 fn default() -> Self {
186 Self {
187 error_code: 0i16,
188 name: Some(""),
189 topic_id: Uuid::default(),
190 is_internal: false,
191 partitions: Vec::new(),
192 topic_authorized_operations: -2_147_483_648i32,
193 unknown_tagged_fields: UnknownTaggedFields::default(),
194 }
195 }
196}
197impl DescribeTopicPartitionsResponseTopic<'_> {
198 #[must_use]
199 pub fn to_owned(
200 &self,
201 ) -> describe_topic_partitions_response::DescribeTopicPartitionsResponseTopic {
202 describe_topic_partitions_response::DescribeTopicPartitionsResponseTopic {
203 error_code: (self.error_code),
204 name: (self.name).map(str::to_owned),
205 topic_id: (self.topic_id),
206 is_internal: (self.is_internal),
207 partitions: (self.partitions)
208 .iter()
209 .map(DescribeTopicPartitionsResponsePartition::to_owned)
210 .collect(),
211 topic_authorized_operations: (self.topic_authorized_operations),
212 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
213 }
214 }
215}
216impl Encode for DescribeTopicPartitionsResponseTopic<'_> {
217 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
218 let flex = version >= 0;
219 if version >= 0 {
220 put_i16(buf, self.error_code);
221 }
222 if version >= 0 {
223 if flex {
224 put_compact_nullable_string(buf, self.name)?;
225 } else {
226 put_nullable_string(buf, self.name)?;
227 }
228 }
229 if version >= 0 {
230 put_uuid(buf, self.topic_id);
231 }
232 if version >= 0 {
233 put_bool(buf, self.is_internal);
234 }
235 if version >= 0 {
236 {
237 put_array_len(buf, (self.partitions).len(), flex)?;
238 for it in &self.partitions {
239 it.encode(buf, version)?;
240 }
241 }
242 }
243 if version >= 0 {
244 put_i32(buf, self.topic_authorized_operations);
245 }
246 if flex {
247 let tagged = WriteTaggedFields::new();
248 tagged.write(buf, &self.unknown_tagged_fields)?;
249 }
250 Ok(())
251 }
252 fn encoded_len(&self, version: i16) -> usize {
253 let flex = version >= 0;
254 let mut n: usize = 0;
255 if version >= 0 {
256 n += 2;
257 }
258 if version >= 0 {
259 n += if flex {
260 compact_nullable_string_len(self.name)
261 } else {
262 nullable_string_len(self.name)
263 };
264 }
265 if version >= 0 {
266 n += 16;
267 }
268 if version >= 0 {
269 n += 1;
270 }
271 if version >= 0 {
272 n += {
273 let prefix = array_len_prefix_len((self.partitions).len(), flex);
274 let body: usize = (self.partitions)
275 .iter()
276 .map(|it| it.encoded_len(version))
277 .sum();
278 prefix + body
279 };
280 }
281 if version >= 0 {
282 n += 4;
283 }
284 if flex {
285 let known_pairs: Vec<(u32, usize)> = Vec::new();
286 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
287 }
288 n
289 }
290}
291impl<'de> DecodeBorrow<'de> for DescribeTopicPartitionsResponseTopic<'de> {
292 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
293 let flex = version >= 0;
294 let mut out = Self::default();
295 if version >= 0 {
296 out.error_code = get_i16(buf)?;
297 }
298 if version >= 0 {
299 out.name = if flex {
300 get_compact_nullable_string_borrowed(buf)?
301 } else {
302 get_nullable_string_borrowed(buf)?
303 };
304 }
305 if version >= 0 {
306 out.topic_id = get_uuid(buf)?;
307 }
308 if version >= 0 {
309 out.is_internal = get_bool(buf)?;
310 }
311 if version >= 0 {
312 out.partitions = {
313 let n = get_array_len(buf, flex)?;
314 let mut v = Vec::with_capacity(n);
315 for _ in 0..n {
316 v.push(DescribeTopicPartitionsResponsePartition::decode_borrow(
317 buf, version,
318 )?);
319 }
320 v
321 };
322 }
323 if version >= 0 {
324 out.topic_authorized_operations = get_i32(buf)?;
325 }
326 if flex {
327 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
328 }
329 Ok(out)
330 }
331}
332#[cfg(test)]
333impl DescribeTopicPartitionsResponseTopic<'_> {
334 #[must_use]
335 pub fn populated(version: i16) -> Self {
336 let mut m = Self::default();
337 if version >= 0 {
338 m.error_code = 1i16;
339 }
340 if version >= 0 {
341 m.name = Some("x");
342 }
343 if version >= 0 {
344 m.topic_id = Uuid([1u8; 16]);
345 }
346 if version >= 0 {
347 m.is_internal = true;
348 }
349 if version >= 0 {
350 m.partitions = vec![DescribeTopicPartitionsResponsePartition::populated(version)];
351 }
352 if version >= 0 {
353 m.topic_authorized_operations = 1i32;
354 }
355 m
356 }
357}
358#[derive(Debug, Clone, PartialEq, Eq)]
359pub struct DescribeTopicPartitionsResponsePartition {
360 pub error_code: i16,
361 pub partition_index: i32,
362 pub leader_id: i32,
363 pub leader_epoch: i32,
364 pub replica_nodes: Vec<i32>,
365 pub isr_nodes: Vec<i32>,
366 pub eligible_leader_replicas: Option<Vec<i32>>,
367 pub last_known_elr: Option<Vec<i32>>,
368 pub offline_replicas: Vec<i32>,
369 pub unknown_tagged_fields: UnknownTaggedFields,
370}
371impl Default for DescribeTopicPartitionsResponsePartition {
372 fn default() -> Self {
373 Self {
374 error_code: 0i16,
375 partition_index: 0i32,
376 leader_id: 0i32,
377 leader_epoch: -1i32,
378 replica_nodes: Vec::new(),
379 isr_nodes: Vec::new(),
380 eligible_leader_replicas: None,
381 last_known_elr: None,
382 offline_replicas: Vec::new(),
383 unknown_tagged_fields: UnknownTaggedFields::default(),
384 }
385 }
386}
387impl DescribeTopicPartitionsResponsePartition {
388 #[must_use]
389 pub fn to_owned(
390 &self,
391 ) -> describe_topic_partitions_response::DescribeTopicPartitionsResponsePartition {
392 describe_topic_partitions_response::DescribeTopicPartitionsResponsePartition {
393 error_code: (self.error_code),
394 partition_index: (self.partition_index),
395 leader_id: (self.leader_id),
396 leader_epoch: (self.leader_epoch),
397 replica_nodes: (self.replica_nodes).clone(),
398 isr_nodes: (self.isr_nodes).clone(),
399 eligible_leader_replicas: (self.eligible_leader_replicas).clone(),
400 last_known_elr: (self.last_known_elr).clone(),
401 offline_replicas: (self.offline_replicas).clone(),
402 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
403 }
404 }
405 fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
406 if version >= 0 {
407 put_i16(buf, self.error_code);
408 }
409 }
410 fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
411 if version >= 0 {
412 put_i32(buf, self.partition_index);
413 }
414 }
415 fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
416 if version >= 0 {
417 put_i32(buf, self.leader_id);
418 }
419 }
420 fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
421 if version >= 0 {
422 put_i32(buf, self.leader_epoch);
423 }
424 }
425 fn encode_field_4<B: BufMut>(
426 &self,
427 buf: &mut B,
428 version: i16,
429 flex: bool,
430 ) -> Result<(), ProtocolError> {
431 if version >= 0 {
432 {
433 put_array_len(buf, (self.replica_nodes).len(), flex)?;
434 for it in &self.replica_nodes {
435 put_i32(buf, *it);
436 }
437 }
438 }
439 Ok(())
440 }
441 fn encode_field_5<B: BufMut>(
442 &self,
443 buf: &mut B,
444 version: i16,
445 flex: bool,
446 ) -> Result<(), ProtocolError> {
447 if version >= 0 {
448 {
449 put_array_len(buf, (self.isr_nodes).len(), flex)?;
450 for it in &self.isr_nodes {
451 put_i32(buf, *it);
452 }
453 }
454 }
455 Ok(())
456 }
457 fn encode_field_6<B: BufMut>(
458 &self,
459 buf: &mut B,
460 version: i16,
461 flex: bool,
462 ) -> Result<(), ProtocolError> {
463 if version >= 0 {
464 {
465 let len = (self.eligible_leader_replicas).as_ref().map(Vec::len);
466 put_nullable_array_len(buf, len, flex)?;
467 if let Some(v) = &self.eligible_leader_replicas {
468 for it in v {
469 put_i32(buf, *it);
470 }
471 }
472 }
473 }
474 Ok(())
475 }
476 fn encode_field_7<B: BufMut>(
477 &self,
478 buf: &mut B,
479 version: i16,
480 flex: bool,
481 ) -> Result<(), ProtocolError> {
482 if version >= 0 {
483 {
484 let len = (self.last_known_elr).as_ref().map(Vec::len);
485 put_nullable_array_len(buf, len, flex)?;
486 if let Some(v) = &self.last_known_elr {
487 for it in v {
488 put_i32(buf, *it);
489 }
490 }
491 }
492 }
493 Ok(())
494 }
495 fn encode_field_8<B: BufMut>(
496 &self,
497 buf: &mut B,
498 version: i16,
499 flex: bool,
500 ) -> Result<(), ProtocolError> {
501 if version >= 0 {
502 {
503 put_array_len(buf, (self.offline_replicas).len(), flex)?;
504 for it in &self.offline_replicas {
505 put_i32(buf, *it);
506 }
507 }
508 }
509 Ok(())
510 }
511 fn encode_tagged_fields<B: BufMut>(
512 &self,
513 buf: &mut B,
514 _version: i16,
515 flex: bool,
516 ) -> Result<(), ProtocolError> {
517 if flex {
518 let tagged = WriteTaggedFields::new();
519 tagged.write(buf, &self.unknown_tagged_fields)?;
520 }
521 Ok(())
522 }
523 fn decode_field_0(
524 out: &mut Self,
525 buf: &mut &[u8],
526 version: i16,
527 _flex: bool,
528 ) -> Result<(), ProtocolError> {
529 if version >= 0 {
530 out.error_code = get_i16(buf)?;
531 }
532 Ok(())
533 }
534 fn decode_field_1(
535 out: &mut Self,
536 buf: &mut &[u8],
537 version: i16,
538 _flex: bool,
539 ) -> Result<(), ProtocolError> {
540 if version >= 0 {
541 out.partition_index = get_i32(buf)?;
542 }
543 Ok(())
544 }
545 fn decode_field_2(
546 out: &mut Self,
547 buf: &mut &[u8],
548 version: i16,
549 _flex: bool,
550 ) -> Result<(), ProtocolError> {
551 if version >= 0 {
552 out.leader_id = get_i32(buf)?;
553 }
554 Ok(())
555 }
556 fn decode_field_3(
557 out: &mut Self,
558 buf: &mut &[u8],
559 version: i16,
560 _flex: bool,
561 ) -> Result<(), ProtocolError> {
562 if version >= 0 {
563 out.leader_epoch = get_i32(buf)?;
564 }
565 Ok(())
566 }
567 fn decode_field_4(
568 out: &mut Self,
569 buf: &mut &[u8],
570 version: i16,
571 flex: bool,
572 ) -> Result<(), ProtocolError> {
573 if version >= 0 {
574 out.replica_nodes = {
575 let n = get_array_len(buf, flex)?;
576 let mut v = Vec::with_capacity(n);
577 for _ in 0..n {
578 v.push(get_i32(buf)?);
579 }
580 v
581 };
582 }
583 Ok(())
584 }
585 fn decode_field_5(
586 out: &mut Self,
587 buf: &mut &[u8],
588 version: i16,
589 flex: bool,
590 ) -> Result<(), ProtocolError> {
591 if version >= 0 {
592 out.isr_nodes = {
593 let n = get_array_len(buf, flex)?;
594 let mut v = Vec::with_capacity(n);
595 for _ in 0..n {
596 v.push(get_i32(buf)?);
597 }
598 v
599 };
600 }
601 Ok(())
602 }
603 fn decode_field_6(
604 out: &mut Self,
605 buf: &mut &[u8],
606 version: i16,
607 flex: bool,
608 ) -> Result<(), ProtocolError> {
609 if version >= 0 {
610 out.eligible_leader_replicas = {
611 let opt = get_nullable_array_len(buf, flex)?;
612 match opt {
613 None => None,
614 Some(n) => {
615 let mut v = Vec::with_capacity(n);
616 for _ in 0..n {
617 v.push(get_i32(buf)?);
618 }
619 Some(v)
620 }
621 }
622 };
623 }
624 Ok(())
625 }
626 fn decode_field_7(
627 out: &mut Self,
628 buf: &mut &[u8],
629 version: i16,
630 flex: bool,
631 ) -> Result<(), ProtocolError> {
632 if version >= 0 {
633 out.last_known_elr = {
634 let opt = get_nullable_array_len(buf, flex)?;
635 match opt {
636 None => None,
637 Some(n) => {
638 let mut v = Vec::with_capacity(n);
639 for _ in 0..n {
640 v.push(get_i32(buf)?);
641 }
642 Some(v)
643 }
644 }
645 };
646 }
647 Ok(())
648 }
649 fn decode_field_8(
650 out: &mut Self,
651 buf: &mut &[u8],
652 version: i16,
653 flex: bool,
654 ) -> Result<(), ProtocolError> {
655 if version >= 0 {
656 out.offline_replicas = {
657 let n = get_array_len(buf, flex)?;
658 let mut v = Vec::with_capacity(n);
659 for _ in 0..n {
660 v.push(get_i32(buf)?);
661 }
662 v
663 };
664 }
665 Ok(())
666 }
667 fn decode_tagged_fields(
668 out: &mut Self,
669 buf: &mut &[u8],
670 _version: i16,
671 flex: bool,
672 ) -> Result<(), ProtocolError> {
673 if flex {
674 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
675 }
676 Ok(())
677 }
678}
679impl Encode for DescribeTopicPartitionsResponsePartition {
680 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
681 let flex = version >= 0;
682 self.encode_field_0(buf, version, flex);
683 self.encode_field_1(buf, version, flex);
684 self.encode_field_2(buf, version, flex);
685 self.encode_field_3(buf, version, flex);
686 self.encode_field_4(buf, version, flex)?;
687 self.encode_field_5(buf, version, flex)?;
688 self.encode_field_6(buf, version, flex)?;
689 self.encode_field_7(buf, version, flex)?;
690 self.encode_field_8(buf, version, flex)?;
691 self.encode_tagged_fields(buf, version, flex)?;
692 Ok(())
693 }
694 fn encoded_len(&self, version: i16) -> usize {
695 let flex = version >= 0;
696 let mut n: usize = 0;
697 if version >= 0 {
698 n += 2;
699 }
700 if version >= 0 {
701 n += 4;
702 }
703 if version >= 0 {
704 n += 4;
705 }
706 if version >= 0 {
707 n += 4;
708 }
709 if version >= 0 {
710 n += {
711 let prefix = array_len_prefix_len((self.replica_nodes).len(), flex);
712 let body: usize = (self.replica_nodes).iter().map(|_| 4).sum();
713 prefix + body
714 };
715 }
716 if version >= 0 {
717 n += {
718 let prefix = array_len_prefix_len((self.isr_nodes).len(), flex);
719 let body: usize = (self.isr_nodes).iter().map(|_| 4).sum();
720 prefix + body
721 };
722 }
723 if version >= 0 {
724 n += {
725 let opt: Option<&Vec<_>> = (self.eligible_leader_replicas).as_ref();
726 let prefix = nullable_array_len_prefix_len(opt.map(Vec::len), flex);
727 let body: usize = opt.map_or(0, |v| v.iter().map(|_| 4).sum());
728 prefix + body
729 };
730 }
731 if version >= 0 {
732 n += {
733 let opt: Option<&Vec<_>> = (self.last_known_elr).as_ref();
734 let prefix = nullable_array_len_prefix_len(opt.map(Vec::len), flex);
735 let body: usize = opt.map_or(0, |v| v.iter().map(|_| 4).sum());
736 prefix + body
737 };
738 }
739 if version >= 0 {
740 n += {
741 let prefix = array_len_prefix_len((self.offline_replicas).len(), flex);
742 let body: usize = (self.offline_replicas).iter().map(|_| 4).sum();
743 prefix + body
744 };
745 }
746 if flex {
747 let known_pairs: Vec<(u32, usize)> = Vec::new();
748 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
749 }
750 n
751 }
752}
753impl<'de> DecodeBorrow<'de> for DescribeTopicPartitionsResponsePartition {
754 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
755 let flex = version >= 0;
756 let mut out = Self::default();
757 Self::decode_field_0(&mut out, buf, version, flex)?;
758 Self::decode_field_1(&mut out, buf, version, flex)?;
759 Self::decode_field_2(&mut out, buf, version, flex)?;
760 Self::decode_field_3(&mut out, buf, version, flex)?;
761 Self::decode_field_4(&mut out, buf, version, flex)?;
762 Self::decode_field_5(&mut out, buf, version, flex)?;
763 Self::decode_field_6(&mut out, buf, version, flex)?;
764 Self::decode_field_7(&mut out, buf, version, flex)?;
765 Self::decode_field_8(&mut out, buf, version, flex)?;
766 Self::decode_tagged_fields(&mut out, buf, version, flex)?;
767 Ok(out)
768 }
769}
770#[cfg(test)]
771impl DescribeTopicPartitionsResponsePartition {
772 #[must_use]
773 pub fn populated(version: i16) -> Self {
774 let mut m = Self::default();
775 if version >= 0 {
776 m.error_code = 1i16;
777 }
778 if version >= 0 {
779 m.partition_index = 1i32;
780 }
781 if version >= 0 {
782 m.leader_id = 1i32;
783 }
784 if version >= 0 {
785 m.leader_epoch = 1i32;
786 }
787 if version >= 0 {
788 m.replica_nodes = vec![1i32];
789 }
790 if version >= 0 {
791 m.isr_nodes = vec![1i32];
792 }
793 if version >= 0 {
794 m.eligible_leader_replicas = Some(vec![1i32]);
795 }
796 if version >= 0 {
797 m.last_known_elr = Some(vec![1i32]);
798 }
799 if version >= 0 {
800 m.offline_replicas = vec![1i32];
801 }
802 m
803 }
804}
805#[derive(Debug, Clone, PartialEq, Eq, Default)]
806pub struct Cursor<'a> {
807 pub topic_name: &'a str,
808 pub partition_index: i32,
809 pub unknown_tagged_fields: UnknownTaggedFields,
810}
811impl Cursor<'_> {
812 #[must_use]
813 pub fn to_owned(&self) -> describe_topic_partitions_response::Cursor {
814 describe_topic_partitions_response::Cursor {
815 topic_name: (self.topic_name).to_owned(),
816 partition_index: (self.partition_index),
817 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
818 }
819 }
820}
821impl Encode for Cursor<'_> {
822 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
823 let flex = version >= 0;
824 if version >= 0 {
825 if flex {
826 put_compact_string(buf, self.topic_name)?;
827 } else {
828 put_string(buf, self.topic_name)?;
829 }
830 }
831 if version >= 0 {
832 put_i32(buf, self.partition_index);
833 }
834 if flex {
835 let tagged = WriteTaggedFields::new();
836 tagged.write(buf, &self.unknown_tagged_fields)?;
837 }
838 Ok(())
839 }
840 fn encoded_len(&self, version: i16) -> usize {
841 let flex = version >= 0;
842 let mut n: usize = 0;
843 if version >= 0 {
844 n += if flex {
845 compact_string_len(self.topic_name)
846 } else {
847 string_len(self.topic_name)
848 };
849 }
850 if version >= 0 {
851 n += 4;
852 }
853 if flex {
854 let known_pairs: Vec<(u32, usize)> = Vec::new();
855 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
856 }
857 n
858 }
859}
860impl<'de> DecodeBorrow<'de> for Cursor<'de> {
861 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
862 let flex = version >= 0;
863 let mut out = Self::default();
864 if version >= 0 {
865 out.topic_name = if flex {
866 get_compact_string_borrowed(buf)?
867 } else {
868 get_string_borrowed(buf)?
869 };
870 }
871 if version >= 0 {
872 out.partition_index = get_i32(buf)?;
873 }
874 if flex {
875 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
876 }
877 Ok(out)
878 }
879}
880#[cfg(test)]
881impl Cursor<'_> {
882 #[must_use]
883 pub fn populated(version: i16) -> Self {
884 let mut m = Self::default();
885 if version >= 0 {
886 m.topic_name = "x";
887 }
888 if version >= 0 {
889 m.partition_index = 1i32;
890 }
891 m
892 }
893}