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