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