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