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