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