Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeTopicPartitionsResponse.owned.rs

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