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 bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
10};
11use crate::primitives::string_bytes::{
12    get_bytes_owned, get_compact_bytes_owned, get_compact_nullable_bytes_owned,
13    get_nullable_bytes_owned, put_bytes, put_compact_bytes, put_compact_nullable_bytes,
14    put_nullable_bytes,
15};
16use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
17use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
18
19pub const API_KEY: i16 = 78;
20pub const MIN_VERSION: i16 = 1;
21pub const MAX_VERSION: i16 = 2;
22pub const FLEXIBLE_MIN: i16 = 0;
23
24#[inline]
25fn is_flexible(version: i16) -> bool {
26    version >= FLEXIBLE_MIN
27}
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                put_compact_nullable_string(buf, self.error_message.as_deref());
57            } else {
58                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 Encode for PartitionData {
314    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
315        let flex = version >= 0;
316        if version >= 0 {
317            put_i32(buf, self.partition_index);
318        }
319        if version >= 0 {
320            put_i16(buf, self.error_code);
321        }
322        if version >= 0 {
323            if flex {
324                put_compact_nullable_string(buf, self.error_message.as_deref());
325            } else {
326                put_nullable_string(buf, self.error_message.as_deref());
327            }
328        }
329        if version >= 0 {
330            put_i16(buf, self.acknowledge_error_code);
331        }
332        if version >= 0 {
333            if flex {
334                put_compact_nullable_string(buf, self.acknowledge_error_message.as_deref());
335            } else {
336                put_nullable_string(buf, self.acknowledge_error_message.as_deref());
337            }
338        }
339        if version >= 0 {
340            self.current_leader.encode(buf, version)?;
341        }
342        if version >= 0 {
343            if version <= 0 {
344                match &self.records {
345                    None => {
346                        if flex {
347                            put_compact_nullable_bytes(buf, None);
348                        } else {
349                            put_nullable_bytes(buf, None);
350                        }
351                    }
352                    Some(__rb) => {
353                        let mut __rb_buf = bytes::BytesMut::new();
354                        <crate::records::RecordsPayload as crate::Encode>::encode(
355                            __rb,
356                            &mut __rb_buf,
357                            version,
358                        )?;
359                        if flex {
360                            put_compact_bytes(buf, &__rb_buf);
361                        } else {
362                            put_bytes(buf, &__rb_buf);
363                        }
364                    }
365                }
366            } else {
367                match &self.records {
368                    None => {
369                        let __rb_buf = bytes::BytesMut::new();
370                        if flex {
371                            put_compact_bytes(buf, &__rb_buf);
372                        } else {
373                            put_bytes(buf, &__rb_buf);
374                        }
375                    }
376                    Some(__rb) => {
377                        let mut __rb_buf = bytes::BytesMut::new();
378                        <crate::records::RecordsPayload as crate::Encode>::encode(
379                            __rb,
380                            &mut __rb_buf,
381                            version,
382                        )?;
383                        if flex {
384                            put_compact_bytes(buf, &__rb_buf);
385                        } else {
386                            put_bytes(buf, &__rb_buf);
387                        }
388                    }
389                }
390            }
391        }
392        if version >= 0 {
393            {
394                crate::primitives::array::put_array_len(buf, (self.acquired_records).len(), flex);
395                for it in &self.acquired_records {
396                    it.encode(buf, version)?;
397                }
398            }
399        }
400        if flex {
401            let tagged = WriteTaggedFields::new();
402            tagged.write(buf, &self.unknown_tagged_fields);
403        }
404        Ok(())
405    }
406    fn encoded_len(&self, version: i16) -> usize {
407        let flex = version >= 0;
408        let mut n: usize = 0;
409        if version >= 0 {
410            n += 4;
411        }
412        if version >= 0 {
413            n += 2;
414        }
415        if version >= 0 {
416            n += if flex {
417                compact_nullable_string_len(self.error_message.as_deref())
418            } else {
419                nullable_string_len(self.error_message.as_deref())
420            };
421        }
422        if version >= 0 {
423            n += 2;
424        }
425        if version >= 0 {
426            n += if flex {
427                compact_nullable_string_len(self.acknowledge_error_message.as_deref())
428            } else {
429                nullable_string_len(self.acknowledge_error_message.as_deref())
430            };
431        }
432        if version >= 0 {
433            n += self.current_leader.encoded_len(version);
434        }
435        if version >= 0 {
436            n += if version <= 0 {
437                match &self.records {
438                    None => {
439                        if flex {
440                            crate::primitives::varint::uvarint_len(0)
441                        } else {
442                            4
443                        }
444                    }
445                    Some(__rb) => {
446                        let __rb_len =
447                            <crate::records::RecordsPayload as crate::Encode>::encoded_len(
448                                __rb, version,
449                            );
450                        if flex {
451                            crate::primitives::string_bytes::compact_bytes_len_from_size(__rb_len)
452                        } else {
453                            4 + __rb_len
454                        }
455                    }
456                }
457            } else {
458                match &self.records {
459                    None => {
460                        if flex {
461                            crate::primitives::string_bytes::compact_bytes_len_from_size(0)
462                        } else {
463                            4
464                        }
465                    }
466                    Some(__rb) => {
467                        let __rb_len =
468                            <crate::records::RecordsPayload as crate::Encode>::encoded_len(
469                                __rb, version,
470                            );
471                        if flex {
472                            crate::primitives::string_bytes::compact_bytes_len_from_size(__rb_len)
473                        } else {
474                            4 + __rb_len
475                        }
476                    }
477                }
478            };
479        }
480        if version >= 0 {
481            n += {
482                let prefix = crate::primitives::array::array_len_prefix_len(
483                    (self.acquired_records).len(),
484                    flex,
485                );
486                let body: usize = (self.acquired_records)
487                    .iter()
488                    .map(|it| it.encoded_len(version))
489                    .sum();
490                prefix + body
491            };
492        }
493        if flex {
494            let known_pairs: Vec<(u32, usize)> = Vec::new();
495            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
496        }
497        n
498    }
499}
500impl Decode<'_> for PartitionData {
501    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
502        let flex = version >= 0;
503        let mut out = Self::default();
504        if version >= 0 {
505            out.partition_index = get_i32(buf)?;
506        }
507        if version >= 0 {
508            out.error_code = get_i16(buf)?;
509        }
510        if version >= 0 {
511            out.error_message = if flex {
512                get_compact_nullable_string_owned(buf)?
513            } else {
514                get_nullable_string_owned(buf)?
515            };
516        }
517        if version >= 0 {
518            out.acknowledge_error_code = get_i16(buf)?;
519        }
520        if version >= 0 {
521            out.acknowledge_error_message = if flex {
522                get_compact_nullable_string_owned(buf)?
523            } else {
524                get_nullable_string_owned(buf)?
525            };
526        }
527        if version >= 0 {
528            out.current_leader = LeaderIdAndEpoch::decode(buf, version)?;
529        }
530        if version >= 0 {
531            out.records = if version <= 0 {
532                {
533                    let __rb_opt = if flex {
534                        get_compact_nullable_bytes_owned(buf)?
535                    } else {
536                        get_nullable_bytes_owned(buf)?
537                    };
538                    match __rb_opt {
539                        None => None,
540                        Some(__rb_bytes) => {
541                            let mut __rb_cur: &[u8] = &__rb_bytes;
542                            Some(crate::records::RecordsPayload::decode_lenient(
543                                &mut __rb_cur,
544                                version,
545                            )?)
546                        }
547                    }
548                }
549            } else {
550                Some({
551                    let __rb_bytes = if flex {
552                        get_compact_bytes_owned(buf)?
553                    } else {
554                        get_bytes_owned(buf)?
555                    };
556                    let mut __rb_cur: &[u8] = &__rb_bytes;
557                    crate::records::RecordsPayload::decode_lenient(&mut __rb_cur, version)?
558                })
559            };
560        }
561        if version >= 0 {
562            out.acquired_records = {
563                let n = crate::primitives::array::get_array_len(buf, flex)?;
564                let mut v = Vec::with_capacity(n);
565                for _ in 0..n {
566                    v.push(AcquiredRecords::decode(buf, version)?);
567                }
568                v
569            };
570        }
571        if flex {
572            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
573        }
574        Ok(out)
575    }
576}
577#[cfg(test)]
578impl PartitionData {
579    #[must_use]
580    pub fn populated(version: i16) -> Self {
581        let mut m = Self::default();
582        if version >= 0 {
583            m.partition_index = 1i32;
584        }
585        if version >= 0 {
586            m.error_code = 1i16;
587        }
588        if version >= 0 {
589            m.error_message = Some("x".to_string());
590        }
591        if version >= 0 {
592            m.acknowledge_error_code = 1i16;
593        }
594        if version >= 0 {
595            m.acknowledge_error_message = Some("x".to_string());
596        }
597        if version >= 0 {
598            m.current_leader = LeaderIdAndEpoch::populated(version);
599        }
600        if version >= 0 {
601            m.acquired_records = vec![AcquiredRecords::populated(version)];
602        }
603        m
604    }
605}
606#[derive(Debug, Clone, PartialEq, Eq, Default)]
607pub struct LeaderIdAndEpoch {
608    pub leader_id: i32,
609    pub leader_epoch: i32,
610    pub unknown_tagged_fields: UnknownTaggedFields,
611}
612impl Encode for LeaderIdAndEpoch {
613    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
614        let flex = version >= 0;
615        if version >= 0 {
616            put_i32(buf, self.leader_id);
617        }
618        if version >= 0 {
619            put_i32(buf, self.leader_epoch);
620        }
621        if flex {
622            let tagged = WriteTaggedFields::new();
623            tagged.write(buf, &self.unknown_tagged_fields);
624        }
625        Ok(())
626    }
627    fn encoded_len(&self, version: i16) -> usize {
628        let flex = version >= 0;
629        let mut n: usize = 0;
630        if version >= 0 {
631            n += 4;
632        }
633        if version >= 0 {
634            n += 4;
635        }
636        if flex {
637            let known_pairs: Vec<(u32, usize)> = Vec::new();
638            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
639        }
640        n
641    }
642}
643impl Decode<'_> for LeaderIdAndEpoch {
644    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
645        let flex = version >= 0;
646        let mut out = Self::default();
647        if version >= 0 {
648            out.leader_id = get_i32(buf)?;
649        }
650        if version >= 0 {
651            out.leader_epoch = get_i32(buf)?;
652        }
653        if flex {
654            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
655        }
656        Ok(out)
657    }
658}
659#[cfg(test)]
660impl LeaderIdAndEpoch {
661    #[must_use]
662    pub fn populated(version: i16) -> Self {
663        let mut m = Self::default();
664        if version >= 0 {
665            m.leader_id = 1i32;
666        }
667        if version >= 0 {
668            m.leader_epoch = 1i32;
669        }
670        m
671    }
672}
673#[derive(Debug, Clone, PartialEq, Eq, Default)]
674pub struct AcquiredRecords {
675    pub first_offset: i64,
676    pub last_offset: i64,
677    pub delivery_count: i16,
678    pub unknown_tagged_fields: UnknownTaggedFields,
679}
680impl Encode for AcquiredRecords {
681    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
682        let flex = version >= 0;
683        if version >= 0 {
684            put_i64(buf, self.first_offset);
685        }
686        if version >= 0 {
687            put_i64(buf, self.last_offset);
688        }
689        if version >= 0 {
690            put_i16(buf, self.delivery_count);
691        }
692        if flex {
693            let tagged = WriteTaggedFields::new();
694            tagged.write(buf, &self.unknown_tagged_fields);
695        }
696        Ok(())
697    }
698    fn encoded_len(&self, version: i16) -> usize {
699        let flex = version >= 0;
700        let mut n: usize = 0;
701        if version >= 0 {
702            n += 8;
703        }
704        if version >= 0 {
705            n += 8;
706        }
707        if version >= 0 {
708            n += 2;
709        }
710        if flex {
711            let known_pairs: Vec<(u32, usize)> = Vec::new();
712            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
713        }
714        n
715    }
716}
717impl Decode<'_> for AcquiredRecords {
718    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
719        let flex = version >= 0;
720        let mut out = Self::default();
721        if version >= 0 {
722            out.first_offset = get_i64(buf)?;
723        }
724        if version >= 0 {
725            out.last_offset = get_i64(buf)?;
726        }
727        if version >= 0 {
728            out.delivery_count = get_i16(buf)?;
729        }
730        if flex {
731            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
732        }
733        Ok(out)
734    }
735}
736#[cfg(test)]
737impl AcquiredRecords {
738    #[must_use]
739    pub fn populated(version: i16) -> Self {
740        let mut m = Self::default();
741        if version >= 0 {
742            m.first_offset = 1i64;
743        }
744        if version >= 0 {
745            m.last_offset = 1i64;
746        }
747        if version >= 0 {
748            m.delivery_count = 1i16;
749        }
750        m
751    }
752}
753#[derive(Debug, Clone, PartialEq, Eq, Default)]
754pub struct NodeEndpoint {
755    pub node_id: i32,
756    pub host: String,
757    pub port: i32,
758    pub rack: Option<String>,
759    pub unknown_tagged_fields: UnknownTaggedFields,
760}
761impl Encode for NodeEndpoint {
762    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
763        let flex = version >= 0;
764        if version >= 0 {
765            put_i32(buf, self.node_id);
766        }
767        if version >= 0 {
768            if flex {
769                put_compact_string(buf, &self.host);
770            } else {
771                put_string(buf, &self.host);
772            }
773        }
774        if version >= 0 {
775            put_i32(buf, self.port);
776        }
777        if version >= 0 {
778            if flex {
779                put_compact_nullable_string(buf, self.rack.as_deref());
780            } else {
781                put_nullable_string(buf, self.rack.as_deref());
782            }
783        }
784        if flex {
785            let tagged = WriteTaggedFields::new();
786            tagged.write(buf, &self.unknown_tagged_fields);
787        }
788        Ok(())
789    }
790    fn encoded_len(&self, version: i16) -> usize {
791        let flex = version >= 0;
792        let mut n: usize = 0;
793        if version >= 0 {
794            n += 4;
795        }
796        if version >= 0 {
797            n += if flex {
798                compact_string_len(&self.host)
799            } else {
800                string_len(&self.host)
801            };
802        }
803        if version >= 0 {
804            n += 4;
805        }
806        if version >= 0 {
807            n += if flex {
808                compact_nullable_string_len(self.rack.as_deref())
809            } else {
810                nullable_string_len(self.rack.as_deref())
811            };
812        }
813        if flex {
814            let known_pairs: Vec<(u32, usize)> = Vec::new();
815            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
816        }
817        n
818    }
819}
820impl Decode<'_> for NodeEndpoint {
821    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
822        let flex = version >= 0;
823        let mut out = Self::default();
824        if version >= 0 {
825            out.node_id = get_i32(buf)?;
826        }
827        if version >= 0 {
828            out.host = if flex {
829                get_compact_string_owned(buf)?
830            } else {
831                get_string_owned(buf)?
832            };
833        }
834        if version >= 0 {
835            out.port = get_i32(buf)?;
836        }
837        if version >= 0 {
838            out.rack = if flex {
839                get_compact_nullable_string_owned(buf)?
840            } else {
841                get_nullable_string_owned(buf)?
842            };
843        }
844        if flex {
845            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
846        }
847        Ok(out)
848    }
849}
850#[cfg(test)]
851impl NodeEndpoint {
852    #[must_use]
853    pub fn populated(version: i16) -> Self {
854        let mut m = Self::default();
855        if version >= 0 {
856            m.node_id = 1i32;
857        }
858        if version >= 0 {
859            m.host = "x".to_string();
860        }
861        if version >= 0 {
862            m.port = 1i32;
863        }
864        if version >= 0 {
865            m.rack = Some("x".to_string());
866        }
867        m
868    }
869}
870
871/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
872/// Only includes fields valid for the given version.
873#[must_use]
874#[allow(unused_comparisons)]
875pub fn default_json(version: i16) -> ::serde_json::Value {
876    let mut obj = ::serde_json::Map::new();
877    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
878    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
879    obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
880    if version >= 1 {
881        obj.insert(
882            "acquisitionLockTimeoutMs".to_string(),
883            ::serde_json::json!(0),
884        );
885    }
886    obj.insert("responses".to_string(), ::serde_json::Value::Array(vec![]));
887    obj.insert(
888        "nodeEndpoints".to_string(),
889        ::serde_json::Value::Array(vec![]),
890    );
891    ::serde_json::Value::Object(obj)
892}