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