Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
FetchSnapshotResponse.borrowed.rs

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