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