Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ShareFetchResponse.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_i16, get_i32, get_i64, put_i16, put_i32, put_i64},
9        string_bytes::{
10            compact_nullable_string_len, compact_string_len, get_bytes_owned,
11            get_compact_bytes_owned, get_compact_nullable_bytes_owned,
12            get_compact_nullable_string_owned, get_compact_string_owned, get_nullable_bytes_owned,
13            get_nullable_string_owned, get_string_owned, nullable_string_len, put_bytes,
14            put_compact_bytes, put_compact_nullable_bytes, put_compact_nullable_string,
15            put_compact_string, put_nullable_bytes, put_nullable_string, put_string, string_len,
16        },
17    },
18    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 78;
21pub const MIN_VERSION: i16 = 1;
22pub const MAX_VERSION: i16 = 2;
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 ShareFetchResponse {
31    pub throttle_time_ms: i32,
32    pub error_code: i16,
33    pub error_message: Option<String>,
34    pub acquisition_lock_timeout_ms: i32,
35    pub responses: Vec<ShareFetchableTopicResponse>,
36    pub node_endpoints: Vec<NodeEndpoint>,
37    pub unknown_tagged_fields: UnknownTaggedFields,
38}
39impl Encode for ShareFetchResponse {
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            put_i16(buf, self.error_code);
53        }
54        if version >= 0 {
55            if flex {
56                let () = put_compact_nullable_string(buf, self.error_message.as_deref());
57            } else {
58                let () = put_nullable_string(buf, self.error_message.as_deref());
59            }
60        }
61        if version >= 1 {
62            put_i32(buf, self.acquisition_lock_timeout_ms);
63        }
64        if version >= 0 {
65            {
66                crate::primitives::array::put_array_len(buf, (self.responses).len(), flex);
67                for it in &self.responses {
68                    it.encode(buf, version)?;
69                }
70            };
71        }
72        if version >= 0 {
73            {
74                crate::primitives::array::put_array_len(buf, (self.node_endpoints).len(), flex);
75                for it in &self.node_endpoints {
76                    it.encode(buf, version)?;
77                }
78            };
79        }
80        if flex {
81            let tagged = WriteTaggedFields::new();
82            tagged.write(buf, &self.unknown_tagged_fields);
83        }
84        Ok(())
85    }
86    fn encoded_len(&self, version: i16) -> usize {
87        let flex = is_flexible(version);
88        let mut n: usize = 0;
89        if version >= 0 {
90            n += 4;
91        }
92        if version >= 0 {
93            n += 2;
94        }
95        if version >= 0 {
96            n += if flex {
97                compact_nullable_string_len(self.error_message.as_deref())
98            } else {
99                nullable_string_len(self.error_message.as_deref())
100            };
101        }
102        if version >= 1 {
103            n += 4;
104        }
105        if version >= 0 {
106            n += {
107                let prefix =
108                    crate::primitives::array::array_len_prefix_len((self.responses).len(), flex);
109                let body: usize = (self.responses)
110                    .iter()
111                    .map(|it| it.encoded_len(version))
112                    .sum();
113                prefix + body
114            };
115        }
116        if version >= 0 {
117            n += {
118                let prefix = crate::primitives::array::array_len_prefix_len(
119                    (self.node_endpoints).len(),
120                    flex,
121                );
122                let body: usize = (self.node_endpoints)
123                    .iter()
124                    .map(|it| it.encoded_len(version))
125                    .sum();
126                prefix + body
127            };
128        }
129        if flex {
130            let known_pairs: Vec<(u32, usize)> = Vec::new();
131            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
132        }
133        n
134    }
135}
136impl Decode<'_> for ShareFetchResponse {
137    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
138        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
139            return Err(ProtocolError::UnsupportedVersion {
140                api_key: API_KEY,
141                version,
142            });
143        }
144        let flex = is_flexible(version);
145        let mut out = Self::default();
146        if version >= 0 {
147            out.throttle_time_ms = get_i32(buf)?;
148        }
149        if version >= 0 {
150            out.error_code = get_i16(buf)?;
151        }
152        if version >= 0 {
153            out.error_message = if flex {
154                get_compact_nullable_string_owned(buf)?
155            } else {
156                get_nullable_string_owned(buf)?
157            };
158        }
159        if version >= 1 {
160            out.acquisition_lock_timeout_ms = get_i32(buf)?;
161        }
162        if version >= 0 {
163            out.responses = {
164                let n = crate::primitives::array::get_array_len(buf, flex)?;
165                let mut v = Vec::with_capacity(n);
166                for _ in 0..n {
167                    v.push(ShareFetchableTopicResponse::decode(buf, version)?);
168                }
169                v
170            };
171        }
172        if version >= 0 {
173            out.node_endpoints = {
174                let n = crate::primitives::array::get_array_len(buf, flex)?;
175                let mut v = Vec::with_capacity(n);
176                for _ in 0..n {
177                    v.push(NodeEndpoint::decode(buf, version)?);
178                }
179                v
180            };
181        }
182        if flex {
183            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
184        }
185        Ok(out)
186    }
187}
188#[cfg(test)]
189impl ShareFetchResponse {
190    #[must_use]
191    pub fn populated(version: i16) -> Self {
192        let mut m = Self::default();
193        if version >= 0 {
194            m.throttle_time_ms = 1i32;
195        }
196        if version >= 0 {
197            m.error_code = 1i16;
198        }
199        if version >= 0 {
200            m.error_message = Some("x".to_string());
201        }
202        if version >= 1 {
203            m.acquisition_lock_timeout_ms = 1i32;
204        }
205        if version >= 0 {
206            m.responses = vec![ShareFetchableTopicResponse::populated(version)];
207        }
208        if version >= 0 {
209            m.node_endpoints = vec![NodeEndpoint::populated(version)];
210        }
211        m
212    }
213}
214#[derive(Debug, Clone, PartialEq, Eq, Default)]
215pub struct ShareFetchableTopicResponse {
216    pub topic_id: crate::primitives::uuid::Uuid,
217    pub partitions: Vec<PartitionData>,
218    pub unknown_tagged_fields: UnknownTaggedFields,
219}
220impl Encode for ShareFetchableTopicResponse {
221    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
222        let flex = version >= 0;
223        if version >= 0 {
224            crate::primitives::uuid::put_uuid(buf, self.topic_id);
225        }
226        if version >= 0 {
227            {
228                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
229                for it in &self.partitions {
230                    it.encode(buf, version)?;
231                }
232            };
233        }
234        if flex {
235            let tagged = WriteTaggedFields::new();
236            tagged.write(buf, &self.unknown_tagged_fields);
237        }
238        Ok(())
239    }
240    fn encoded_len(&self, version: i16) -> usize {
241        let flex = version >= 0;
242        let mut n: usize = 0;
243        if version >= 0 {
244            n += 16;
245        }
246        if version >= 0 {
247            n += {
248                let prefix =
249                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
250                let body: usize = (self.partitions)
251                    .iter()
252                    .map(|it| it.encoded_len(version))
253                    .sum();
254                prefix + body
255            };
256        }
257        if flex {
258            let known_pairs: Vec<(u32, usize)> = Vec::new();
259            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
260        }
261        n
262    }
263}
264impl Decode<'_> for ShareFetchableTopicResponse {
265    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
266        let flex = version >= 0;
267        let mut out = Self::default();
268        if version >= 0 {
269            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
270        }
271        if version >= 0 {
272            out.partitions = {
273                let n = crate::primitives::array::get_array_len(buf, flex)?;
274                let mut v = Vec::with_capacity(n);
275                for _ in 0..n {
276                    v.push(PartitionData::decode(buf, version)?);
277                }
278                v
279            };
280        }
281        if flex {
282            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
283        }
284        Ok(out)
285    }
286}
287#[cfg(test)]
288impl ShareFetchableTopicResponse {
289    #[must_use]
290    pub fn populated(version: i16) -> Self {
291        let mut m = Self::default();
292        if version >= 0 {
293            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
294        }
295        if version >= 0 {
296            m.partitions = vec![PartitionData::populated(version)];
297        }
298        m
299    }
300}
301#[derive(Debug, Clone, PartialEq, Eq, Default)]
302pub struct PartitionData {
303    pub partition_index: i32,
304    pub error_code: i16,
305    pub error_message: Option<String>,
306    pub acknowledge_error_code: i16,
307    pub acknowledge_error_message: Option<String>,
308    pub current_leader: LeaderIdAndEpoch,
309    pub records: Option<crate::records::RecordsPayload>,
310    pub acquired_records: Vec<AcquiredRecords>,
311    pub unknown_tagged_fields: UnknownTaggedFields,
312}
313impl PartitionData {
314    fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
315        if version >= 0 {
316            put_i32(buf, self.partition_index);
317        }
318    }
319    fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
320        if version >= 0 {
321            put_i16(buf, self.error_code);
322        }
323    }
324    fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
325        if version >= 0 {
326            if flex {
327                let () = put_compact_nullable_string(buf, self.error_message.as_deref());
328            } else {
329                let () = put_nullable_string(buf, self.error_message.as_deref());
330            }
331        }
332    }
333    fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
334        if version >= 0 {
335            put_i16(buf, self.acknowledge_error_code);
336        }
337    }
338    fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
339        if version >= 0 {
340            if flex {
341                let () =
342                    put_compact_nullable_string(buf, self.acknowledge_error_message.as_deref());
343            } else {
344                let () = put_nullable_string(buf, self.acknowledge_error_message.as_deref());
345            }
346        }
347    }
348    fn encode_field_5<B: BufMut>(
349        &self,
350        buf: &mut B,
351        version: i16,
352        _flex: bool,
353    ) -> Result<(), ProtocolError> {
354        if version >= 0 {
355            self.current_leader.encode(buf, version)?;
356        }
357        Ok(())
358    }
359    fn encode_field_6<B: BufMut>(
360        &self,
361        buf: &mut B,
362        version: i16,
363        flex: bool,
364    ) -> Result<(), ProtocolError> {
365        if version >= 0 {
366            if version <= 0 {
367                match &self.records {
368                    None => {
369                        if flex {
370                            let () = put_compact_nullable_bytes(buf, None);
371                        } else {
372                            let () = put_nullable_bytes(buf, None);
373                        }
374                    }
375                    Some(__rb) => {
376                        let mut __rb_buf = bytes::BytesMut::new();
377                        <crate::records::RecordsPayload as crate::Encode>::encode(
378                            __rb,
379                            &mut __rb_buf,
380                            version,
381                        )?;
382                        if flex {
383                            let () = put_compact_bytes(buf, &__rb_buf);
384                        } else {
385                            let () = put_bytes(buf, &__rb_buf);
386                        }
387                    }
388                }
389            } else {
390                match &self.records {
391                    None => {
392                        let __rb_buf = bytes::BytesMut::new();
393                        if flex {
394                            let () = put_compact_bytes(buf, &__rb_buf);
395                        } else {
396                            let () = put_bytes(buf, &__rb_buf);
397                        }
398                    }
399                    Some(__rb) => {
400                        let mut __rb_buf = bytes::BytesMut::new();
401                        <crate::records::RecordsPayload as crate::Encode>::encode(
402                            __rb,
403                            &mut __rb_buf,
404                            version,
405                        )?;
406                        if flex {
407                            let () = put_compact_bytes(buf, &__rb_buf);
408                        } else {
409                            let () = put_bytes(buf, &__rb_buf);
410                        }
411                    }
412                }
413            }
414        }
415        Ok(())
416    }
417    fn encode_field_7<B: BufMut>(
418        &self,
419        buf: &mut B,
420        version: i16,
421        flex: bool,
422    ) -> Result<(), ProtocolError> {
423        if version >= 0 {
424            {
425                crate::primitives::array::put_array_len(buf, (self.acquired_records).len(), flex);
426                for it in &self.acquired_records {
427                    it.encode(buf, version)?;
428                }
429            };
430        }
431        Ok(())
432    }
433    fn encode_tagged_fields<B: BufMut>(&self, buf: &mut B, _version: i16, flex: bool) {
434        if flex {
435            let tagged = WriteTaggedFields::new();
436            tagged.write(buf, &self.unknown_tagged_fields);
437        }
438    }
439    fn decode_field_0<B: Buf>(
440        out: &mut Self,
441        buf: &mut B,
442        version: i16,
443        _flex: bool,
444    ) -> Result<(), ProtocolError> {
445        if version >= 0 {
446            out.partition_index = get_i32(buf)?;
447        }
448        Ok(())
449    }
450    fn decode_field_1<B: Buf>(
451        out: &mut Self,
452        buf: &mut B,
453        version: i16,
454        _flex: bool,
455    ) -> Result<(), ProtocolError> {
456        if version >= 0 {
457            out.error_code = get_i16(buf)?;
458        }
459        Ok(())
460    }
461    fn decode_field_2<B: Buf>(
462        out: &mut Self,
463        buf: &mut B,
464        version: i16,
465        flex: bool,
466    ) -> Result<(), ProtocolError> {
467        if version >= 0 {
468            out.error_message = if flex {
469                get_compact_nullable_string_owned(buf)?
470            } else {
471                get_nullable_string_owned(buf)?
472            };
473        }
474        Ok(())
475    }
476    fn decode_field_3<B: Buf>(
477        out: &mut Self,
478        buf: &mut B,
479        version: i16,
480        _flex: bool,
481    ) -> Result<(), ProtocolError> {
482        if version >= 0 {
483            out.acknowledge_error_code = get_i16(buf)?;
484        }
485        Ok(())
486    }
487    fn decode_field_4<B: Buf>(
488        out: &mut Self,
489        buf: &mut B,
490        version: i16,
491        flex: bool,
492    ) -> Result<(), ProtocolError> {
493        if version >= 0 {
494            out.acknowledge_error_message = if flex {
495                get_compact_nullable_string_owned(buf)?
496            } else {
497                get_nullable_string_owned(buf)?
498            };
499        }
500        Ok(())
501    }
502    fn decode_field_5<B: Buf>(
503        out: &mut Self,
504        buf: &mut B,
505        version: i16,
506        _flex: bool,
507    ) -> Result<(), ProtocolError> {
508        if version >= 0 {
509            out.current_leader = LeaderIdAndEpoch::decode(buf, version)?;
510        }
511        Ok(())
512    }
513    fn decode_field_6<B: Buf>(
514        out: &mut Self,
515        buf: &mut B,
516        version: i16,
517        flex: bool,
518    ) -> Result<(), ProtocolError> {
519        if version >= 0 {
520            out.records = if version <= 0 {
521                {
522                    let __rb_opt = if flex {
523                        get_compact_nullable_bytes_owned(buf)?
524                    } else {
525                        get_nullable_bytes_owned(buf)?
526                    };
527                    match __rb_opt {
528                        None => None,
529                        Some(__rb_bytes) => {
530                            let mut __rb_cur: &[u8] = &__rb_bytes;
531                            Some(crate::records::RecordsPayload::decode_lenient(
532                                &mut __rb_cur,
533                                version,
534                            )?)
535                        }
536                    }
537                }
538            } else {
539                Some({
540                    let __rb_bytes = if flex {
541                        get_compact_bytes_owned(buf)?
542                    } else {
543                        get_bytes_owned(buf)?
544                    };
545                    let mut __rb_cur: &[u8] = &__rb_bytes;
546                    crate::records::RecordsPayload::decode_lenient(&mut __rb_cur, version)?
547                })
548            };
549        }
550        Ok(())
551    }
552    fn decode_field_7<B: Buf>(
553        out: &mut Self,
554        buf: &mut B,
555        version: i16,
556        flex: bool,
557    ) -> Result<(), ProtocolError> {
558        if version >= 0 {
559            out.acquired_records = {
560                let n = crate::primitives::array::get_array_len(buf, flex)?;
561                let mut v = Vec::with_capacity(n);
562                for _ in 0..n {
563                    v.push(AcquiredRecords::decode(buf, version)?);
564                }
565                v
566            };
567        }
568        Ok(())
569    }
570    fn decode_tagged_fields<B: Buf>(
571        out: &mut Self,
572        buf: &mut B,
573        _version: i16,
574        flex: bool,
575    ) -> Result<(), ProtocolError> {
576        if flex {
577            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
578        }
579        Ok(())
580    }
581}
582impl Encode for PartitionData {
583    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
584        let flex = version >= 0;
585        self.encode_field_0(buf, version, flex);
586        self.encode_field_1(buf, version, flex);
587        self.encode_field_2(buf, version, flex);
588        self.encode_field_3(buf, version, flex);
589        self.encode_field_4(buf, version, flex);
590        self.encode_field_5(buf, version, flex)?;
591        self.encode_field_6(buf, version, flex)?;
592        self.encode_field_7(buf, version, flex)?;
593        self.encode_tagged_fields(buf, version, flex);
594        Ok(())
595    }
596    fn encoded_len(&self, version: i16) -> usize {
597        let flex = version >= 0;
598        let mut n: usize = 0;
599        if version >= 0 {
600            n += 4;
601        }
602        if version >= 0 {
603            n += 2;
604        }
605        if version >= 0 {
606            n += if flex {
607                compact_nullable_string_len(self.error_message.as_deref())
608            } else {
609                nullable_string_len(self.error_message.as_deref())
610            };
611        }
612        if version >= 0 {
613            n += 2;
614        }
615        if version >= 0 {
616            n += if flex {
617                compact_nullable_string_len(self.acknowledge_error_message.as_deref())
618            } else {
619                nullable_string_len(self.acknowledge_error_message.as_deref())
620            };
621        }
622        if version >= 0 {
623            n += self.current_leader.encoded_len(version);
624        }
625        if version >= 0 {
626            n += if version <= 0 {
627                match &self.records {
628                    None => {
629                        if flex {
630                            crate::primitives::varint::uvarint_len(0)
631                        } else {
632                            4
633                        }
634                    }
635                    Some(__rb) => {
636                        let __rb_len =
637                            <crate::records::RecordsPayload as crate::Encode>::encoded_len(
638                                __rb, version,
639                            );
640                        if flex {
641                            crate::primitives::string_bytes::compact_bytes_len_from_size(__rb_len)
642                        } else {
643                            4 + __rb_len
644                        }
645                    }
646                }
647            } else {
648                match &self.records {
649                    None => {
650                        if flex {
651                            crate::primitives::string_bytes::compact_bytes_len_from_size(0)
652                        } else {
653                            4
654                        }
655                    }
656                    Some(__rb) => {
657                        let __rb_len =
658                            <crate::records::RecordsPayload as crate::Encode>::encoded_len(
659                                __rb, version,
660                            );
661                        if flex {
662                            crate::primitives::string_bytes::compact_bytes_len_from_size(__rb_len)
663                        } else {
664                            4 + __rb_len
665                        }
666                    }
667                }
668            };
669        }
670        if version >= 0 {
671            n += {
672                let prefix = crate::primitives::array::array_len_prefix_len(
673                    (self.acquired_records).len(),
674                    flex,
675                );
676                let body: usize = (self.acquired_records)
677                    .iter()
678                    .map(|it| it.encoded_len(version))
679                    .sum();
680                prefix + body
681            };
682        }
683        if flex {
684            let known_pairs: Vec<(u32, usize)> = Vec::new();
685            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
686        }
687        n
688    }
689}
690impl Decode<'_> for PartitionData {
691    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
692        let flex = version >= 0;
693        let mut out = Self::default();
694        Self::decode_field_0(&mut out, buf, version, flex)?;
695        Self::decode_field_1(&mut out, buf, version, flex)?;
696        Self::decode_field_2(&mut out, buf, version, flex)?;
697        Self::decode_field_3(&mut out, buf, version, flex)?;
698        Self::decode_field_4(&mut out, buf, version, flex)?;
699        Self::decode_field_5(&mut out, buf, version, flex)?;
700        Self::decode_field_6(&mut out, buf, version, flex)?;
701        Self::decode_field_7(&mut out, buf, version, flex)?;
702        Self::decode_tagged_fields(&mut out, buf, version, flex)?;
703        Ok(out)
704    }
705}
706#[cfg(test)]
707impl PartitionData {
708    #[must_use]
709    pub fn populated(version: i16) -> Self {
710        let mut m = Self::default();
711        if version >= 0 {
712            m.partition_index = 1i32;
713        }
714        if version >= 0 {
715            m.error_code = 1i16;
716        }
717        if version >= 0 {
718            m.error_message = Some("x".to_string());
719        }
720        if version >= 0 {
721            m.acknowledge_error_code = 1i16;
722        }
723        if version >= 0 {
724            m.acknowledge_error_message = Some("x".to_string());
725        }
726        if version >= 0 {
727            m.current_leader = LeaderIdAndEpoch::populated(version);
728        }
729        if version >= 0 {
730            m.acquired_records = vec![AcquiredRecords::populated(version)];
731        }
732        m
733    }
734}
735#[derive(Debug, Clone, PartialEq, Eq, Default)]
736pub struct LeaderIdAndEpoch {
737    pub leader_id: i32,
738    pub leader_epoch: i32,
739    pub unknown_tagged_fields: UnknownTaggedFields,
740}
741impl Encode for LeaderIdAndEpoch {
742    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
743        let flex = version >= 0;
744        if version >= 0 {
745            put_i32(buf, self.leader_id);
746        }
747        if version >= 0 {
748            put_i32(buf, self.leader_epoch);
749        }
750        if flex {
751            let tagged = WriteTaggedFields::new();
752            tagged.write(buf, &self.unknown_tagged_fields);
753        }
754        Ok(())
755    }
756    fn encoded_len(&self, version: i16) -> usize {
757        let flex = version >= 0;
758        let mut n: usize = 0;
759        if version >= 0 {
760            n += 4;
761        }
762        if version >= 0 {
763            n += 4;
764        }
765        if flex {
766            let known_pairs: Vec<(u32, usize)> = Vec::new();
767            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
768        }
769        n
770    }
771}
772impl Decode<'_> for LeaderIdAndEpoch {
773    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
774        let flex = version >= 0;
775        let mut out = Self::default();
776        if version >= 0 {
777            out.leader_id = get_i32(buf)?;
778        }
779        if version >= 0 {
780            out.leader_epoch = get_i32(buf)?;
781        }
782        if flex {
783            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
784        }
785        Ok(out)
786    }
787}
788#[cfg(test)]
789impl LeaderIdAndEpoch {
790    #[must_use]
791    pub fn populated(version: i16) -> Self {
792        let mut m = Self::default();
793        if version >= 0 {
794            m.leader_id = 1i32;
795        }
796        if version >= 0 {
797            m.leader_epoch = 1i32;
798        }
799        m
800    }
801}
802#[derive(Debug, Clone, PartialEq, Eq, Default)]
803pub struct AcquiredRecords {
804    pub first_offset: i64,
805    pub last_offset: i64,
806    pub delivery_count: i16,
807    pub unknown_tagged_fields: UnknownTaggedFields,
808}
809impl Encode for AcquiredRecords {
810    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
811        let flex = version >= 0;
812        if version >= 0 {
813            put_i64(buf, self.first_offset);
814        }
815        if version >= 0 {
816            put_i64(buf, self.last_offset);
817        }
818        if version >= 0 {
819            put_i16(buf, self.delivery_count);
820        }
821        if flex {
822            let tagged = WriteTaggedFields::new();
823            tagged.write(buf, &self.unknown_tagged_fields);
824        }
825        Ok(())
826    }
827    fn encoded_len(&self, version: i16) -> usize {
828        let flex = version >= 0;
829        let mut n: usize = 0;
830        if version >= 0 {
831            n += 8;
832        }
833        if version >= 0 {
834            n += 8;
835        }
836        if version >= 0 {
837            n += 2;
838        }
839        if flex {
840            let known_pairs: Vec<(u32, usize)> = Vec::new();
841            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
842        }
843        n
844    }
845}
846impl Decode<'_> for AcquiredRecords {
847    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
848        let flex = version >= 0;
849        let mut out = Self::default();
850        if version >= 0 {
851            out.first_offset = get_i64(buf)?;
852        }
853        if version >= 0 {
854            out.last_offset = get_i64(buf)?;
855        }
856        if version >= 0 {
857            out.delivery_count = get_i16(buf)?;
858        }
859        if flex {
860            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
861        }
862        Ok(out)
863    }
864}
865#[cfg(test)]
866impl AcquiredRecords {
867    #[must_use]
868    pub fn populated(version: i16) -> Self {
869        let mut m = Self::default();
870        if version >= 0 {
871            m.first_offset = 1i64;
872        }
873        if version >= 0 {
874            m.last_offset = 1i64;
875        }
876        if version >= 0 {
877            m.delivery_count = 1i16;
878        }
879        m
880    }
881}
882#[derive(Debug, Clone, PartialEq, Eq, Default)]
883pub struct NodeEndpoint {
884    pub node_id: i32,
885    pub host: String,
886    pub port: i32,
887    pub rack: Option<String>,
888    pub unknown_tagged_fields: UnknownTaggedFields,
889}
890impl Encode for NodeEndpoint {
891    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
892        let flex = version >= 0;
893        if version >= 0 {
894            put_i32(buf, self.node_id);
895        }
896        if version >= 0 {
897            if flex {
898                let () = put_compact_string(buf, &self.host);
899            } else {
900                let () = put_string(buf, &self.host);
901            }
902        }
903        if version >= 0 {
904            put_i32(buf, self.port);
905        }
906        if version >= 0 {
907            if flex {
908                let () = put_compact_nullable_string(buf, self.rack.as_deref());
909            } else {
910                let () = put_nullable_string(buf, self.rack.as_deref());
911            }
912        }
913        if flex {
914            let tagged = WriteTaggedFields::new();
915            tagged.write(buf, &self.unknown_tagged_fields);
916        }
917        Ok(())
918    }
919    fn encoded_len(&self, version: i16) -> usize {
920        let flex = version >= 0;
921        let mut n: usize = 0;
922        if version >= 0 {
923            n += 4;
924        }
925        if version >= 0 {
926            n += if flex {
927                compact_string_len(&self.host)
928            } else {
929                string_len(&self.host)
930            };
931        }
932        if version >= 0 {
933            n += 4;
934        }
935        if version >= 0 {
936            n += if flex {
937                compact_nullable_string_len(self.rack.as_deref())
938            } else {
939                nullable_string_len(self.rack.as_deref())
940            };
941        }
942        if flex {
943            let known_pairs: Vec<(u32, usize)> = Vec::new();
944            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
945        }
946        n
947    }
948}
949impl Decode<'_> for NodeEndpoint {
950    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
951        let flex = version >= 0;
952        let mut out = Self::default();
953        if version >= 0 {
954            out.node_id = get_i32(buf)?;
955        }
956        if version >= 0 {
957            out.host = if flex {
958                get_compact_string_owned(buf)?
959            } else {
960                get_string_owned(buf)?
961            };
962        }
963        if version >= 0 {
964            out.port = get_i32(buf)?;
965        }
966        if version >= 0 {
967            out.rack = if flex {
968                get_compact_nullable_string_owned(buf)?
969            } else {
970                get_nullable_string_owned(buf)?
971            };
972        }
973        if flex {
974            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
975        }
976        Ok(out)
977    }
978}
979#[cfg(test)]
980impl NodeEndpoint {
981    #[must_use]
982    pub fn populated(version: i16) -> Self {
983        let mut m = Self::default();
984        if version >= 0 {
985            m.node_id = 1i32;
986        }
987        if version >= 0 {
988            m.host = "x".to_string();
989        }
990        if version >= 0 {
991            m.port = 1i32;
992        }
993        if version >= 0 {
994            m.rack = Some("x".to_string());
995        }
996        m
997    }
998}
999/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
1000/// Only includes fields valid for the given version.
1001#[must_use]
1002#[allow(unused_comparisons)]
1003pub fn default_json(version: i16) -> ::serde_json::Value {
1004    let mut obj = ::serde_json::Map::new();
1005    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
1006    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
1007    obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
1008    if version >= 1 {
1009        obj.insert(
1010            "acquisitionLockTimeoutMs".to_string(),
1011            ::serde_json::json!(0),
1012        );
1013    }
1014    obj.insert("responses".to_string(), ::serde_json::Value::Array(vec![]));
1015    obj.insert(
1016        "nodeEndpoints".to_string(),
1017        ::serde_json::Value::Array(vec![]),
1018    );
1019    ::serde_json::Value::Object(obj)
1020}