Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ShareFetchResponse.owned.rs

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