1#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15 buf::{ByteBuf, ByteBufMut},
16 compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17 Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct Assignment {
24 pub topic_partitions: Vec<TopicPartitions>,
28
29 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
31}
32
33impl Assignment {
34 pub fn with_topic_partitions(mut self, value: Vec<TopicPartitions>) -> Self {
40 self.topic_partitions = value;
41 self
42 }
43 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
45 self.unknown_tagged_fields = value;
46 self
47 }
48 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
50 self.unknown_tagged_fields.insert(key, value);
51 self
52 }
53}
54
55#[cfg(feature = "broker")]
56impl Encodable for Assignment {
57 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
58 if version < 0 || version > 1 {
59 bail!("specified version not supported by this message type");
60 }
61 types::CompactArray(types::Struct { version }).encode(buf, &self.topic_partitions)?;
62 let num_tagged_fields = self.unknown_tagged_fields.len();
63 if num_tagged_fields > std::u32::MAX as usize {
64 bail!(
65 "Too many tagged fields to encode ({} fields)",
66 num_tagged_fields
67 );
68 }
69 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
70
71 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
72 Ok(())
73 }
74 fn compute_size(&self, version: i16) -> Result<usize> {
75 let mut total_size = 0;
76 total_size +=
77 types::CompactArray(types::Struct { version }).compute_size(&self.topic_partitions)?;
78 let num_tagged_fields = self.unknown_tagged_fields.len();
79 if num_tagged_fields > std::u32::MAX as usize {
80 bail!(
81 "Too many tagged fields to encode ({} fields)",
82 num_tagged_fields
83 );
84 }
85 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
86
87 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
88 Ok(total_size)
89 }
90}
91
92#[cfg(feature = "client")]
93impl Decodable for Assignment {
94 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
95 if version < 0 || version > 1 {
96 bail!("specified version not supported by this message type");
97 }
98 let topic_partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
99 let mut unknown_tagged_fields = BTreeMap::new();
100 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
101 for _ in 0..num_tagged_fields {
102 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
103 let size: u32 = types::UnsignedVarInt.decode(buf)?;
104 let unknown_value = buf.try_get_bytes(size as usize)?;
105 unknown_tagged_fields.insert(tag as i32, unknown_value);
106 }
107 Ok(Self {
108 topic_partitions,
109 unknown_tagged_fields,
110 })
111 }
112}
113
114impl Default for Assignment {
115 fn default() -> Self {
116 Self {
117 topic_partitions: Default::default(),
118 unknown_tagged_fields: BTreeMap::new(),
119 }
120 }
121}
122
123impl Message for Assignment {
124 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
125 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
126}
127
128#[non_exhaustive]
130#[derive(Debug, Clone, PartialEq)]
131pub struct ConsumerGroupDescribeResponse {
132 pub throttle_time_ms: i32,
136
137 pub groups: Vec<DescribedGroup>,
141
142 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
144}
145
146impl ConsumerGroupDescribeResponse {
147 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
153 self.throttle_time_ms = value;
154 self
155 }
156 pub fn with_groups(mut self, value: Vec<DescribedGroup>) -> Self {
162 self.groups = value;
163 self
164 }
165 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
167 self.unknown_tagged_fields = value;
168 self
169 }
170 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
172 self.unknown_tagged_fields.insert(key, value);
173 self
174 }
175}
176
177#[cfg(feature = "broker")]
178impl Encodable for ConsumerGroupDescribeResponse {
179 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
180 if version < 0 || version > 1 {
181 bail!("specified version not supported by this message type");
182 }
183 types::Int32.encode(buf, &self.throttle_time_ms)?;
184 types::CompactArray(types::Struct { version }).encode(buf, &self.groups)?;
185 let num_tagged_fields = self.unknown_tagged_fields.len();
186 if num_tagged_fields > std::u32::MAX as usize {
187 bail!(
188 "Too many tagged fields to encode ({} fields)",
189 num_tagged_fields
190 );
191 }
192 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
193
194 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
195 Ok(())
196 }
197 fn compute_size(&self, version: i16) -> Result<usize> {
198 let mut total_size = 0;
199 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
200 total_size += types::CompactArray(types::Struct { version }).compute_size(&self.groups)?;
201 let num_tagged_fields = self.unknown_tagged_fields.len();
202 if num_tagged_fields > std::u32::MAX as usize {
203 bail!(
204 "Too many tagged fields to encode ({} fields)",
205 num_tagged_fields
206 );
207 }
208 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
209
210 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
211 Ok(total_size)
212 }
213}
214
215#[cfg(feature = "client")]
216impl Decodable for ConsumerGroupDescribeResponse {
217 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
218 if version < 0 || version > 1 {
219 bail!("specified version not supported by this message type");
220 }
221 let throttle_time_ms = types::Int32.decode(buf)?;
222 let groups = types::CompactArray(types::Struct { version }).decode(buf)?;
223 let mut unknown_tagged_fields = BTreeMap::new();
224 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
225 for _ in 0..num_tagged_fields {
226 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
227 let size: u32 = types::UnsignedVarInt.decode(buf)?;
228 let unknown_value = buf.try_get_bytes(size as usize)?;
229 unknown_tagged_fields.insert(tag as i32, unknown_value);
230 }
231 Ok(Self {
232 throttle_time_ms,
233 groups,
234 unknown_tagged_fields,
235 })
236 }
237}
238
239impl Default for ConsumerGroupDescribeResponse {
240 fn default() -> Self {
241 Self {
242 throttle_time_ms: 0,
243 groups: Default::default(),
244 unknown_tagged_fields: BTreeMap::new(),
245 }
246 }
247}
248
249impl Message for ConsumerGroupDescribeResponse {
250 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
251 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
252}
253
254#[non_exhaustive]
256#[derive(Debug, Clone, PartialEq)]
257pub struct DescribedGroup {
258 pub error_code: i16,
262
263 pub error_message: Option<StrBytes>,
267
268 pub group_id: super::GroupId,
272
273 pub group_state: StrBytes,
277
278 pub group_epoch: i32,
282
283 pub assignment_epoch: i32,
287
288 pub assignor_name: StrBytes,
292
293 pub members: Vec<Member>,
297
298 pub authorized_operations: i32,
302
303 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
305}
306
307impl DescribedGroup {
308 pub fn with_error_code(mut self, value: i16) -> Self {
314 self.error_code = value;
315 self
316 }
317 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
323 self.error_message = value;
324 self
325 }
326 pub fn with_group_id(mut self, value: super::GroupId) -> Self {
332 self.group_id = value;
333 self
334 }
335 pub fn with_group_state(mut self, value: StrBytes) -> Self {
341 self.group_state = value;
342 self
343 }
344 pub fn with_group_epoch(mut self, value: i32) -> Self {
350 self.group_epoch = value;
351 self
352 }
353 pub fn with_assignment_epoch(mut self, value: i32) -> Self {
359 self.assignment_epoch = value;
360 self
361 }
362 pub fn with_assignor_name(mut self, value: StrBytes) -> Self {
368 self.assignor_name = value;
369 self
370 }
371 pub fn with_members(mut self, value: Vec<Member>) -> Self {
377 self.members = value;
378 self
379 }
380 pub fn with_authorized_operations(mut self, value: i32) -> Self {
386 self.authorized_operations = value;
387 self
388 }
389 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
391 self.unknown_tagged_fields = value;
392 self
393 }
394 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
396 self.unknown_tagged_fields.insert(key, value);
397 self
398 }
399}
400
401#[cfg(feature = "broker")]
402impl Encodable for DescribedGroup {
403 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
404 if version < 0 || version > 1 {
405 bail!("specified version not supported by this message type");
406 }
407 types::Int16.encode(buf, &self.error_code)?;
408 types::CompactString.encode(buf, &self.error_message)?;
409 types::CompactString.encode(buf, &self.group_id)?;
410 types::CompactString.encode(buf, &self.group_state)?;
411 types::Int32.encode(buf, &self.group_epoch)?;
412 types::Int32.encode(buf, &self.assignment_epoch)?;
413 types::CompactString.encode(buf, &self.assignor_name)?;
414 types::CompactArray(types::Struct { version }).encode(buf, &self.members)?;
415 types::Int32.encode(buf, &self.authorized_operations)?;
416 let num_tagged_fields = self.unknown_tagged_fields.len();
417 if num_tagged_fields > std::u32::MAX as usize {
418 bail!(
419 "Too many tagged fields to encode ({} fields)",
420 num_tagged_fields
421 );
422 }
423 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
424
425 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
426 Ok(())
427 }
428 fn compute_size(&self, version: i16) -> Result<usize> {
429 let mut total_size = 0;
430 total_size += types::Int16.compute_size(&self.error_code)?;
431 total_size += types::CompactString.compute_size(&self.error_message)?;
432 total_size += types::CompactString.compute_size(&self.group_id)?;
433 total_size += types::CompactString.compute_size(&self.group_state)?;
434 total_size += types::Int32.compute_size(&self.group_epoch)?;
435 total_size += types::Int32.compute_size(&self.assignment_epoch)?;
436 total_size += types::CompactString.compute_size(&self.assignor_name)?;
437 total_size += types::CompactArray(types::Struct { version }).compute_size(&self.members)?;
438 total_size += types::Int32.compute_size(&self.authorized_operations)?;
439 let num_tagged_fields = self.unknown_tagged_fields.len();
440 if num_tagged_fields > std::u32::MAX as usize {
441 bail!(
442 "Too many tagged fields to encode ({} fields)",
443 num_tagged_fields
444 );
445 }
446 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
447
448 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
449 Ok(total_size)
450 }
451}
452
453#[cfg(feature = "client")]
454impl Decodable for DescribedGroup {
455 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
456 if version < 0 || version > 1 {
457 bail!("specified version not supported by this message type");
458 }
459 let error_code = types::Int16.decode(buf)?;
460 let error_message = types::CompactString.decode(buf)?;
461 let group_id = types::CompactString.decode(buf)?;
462 let group_state = types::CompactString.decode(buf)?;
463 let group_epoch = types::Int32.decode(buf)?;
464 let assignment_epoch = types::Int32.decode(buf)?;
465 let assignor_name = types::CompactString.decode(buf)?;
466 let members = types::CompactArray(types::Struct { version }).decode(buf)?;
467 let authorized_operations = types::Int32.decode(buf)?;
468 let mut unknown_tagged_fields = BTreeMap::new();
469 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
470 for _ in 0..num_tagged_fields {
471 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
472 let size: u32 = types::UnsignedVarInt.decode(buf)?;
473 let unknown_value = buf.try_get_bytes(size as usize)?;
474 unknown_tagged_fields.insert(tag as i32, unknown_value);
475 }
476 Ok(Self {
477 error_code,
478 error_message,
479 group_id,
480 group_state,
481 group_epoch,
482 assignment_epoch,
483 assignor_name,
484 members,
485 authorized_operations,
486 unknown_tagged_fields,
487 })
488 }
489}
490
491impl Default for DescribedGroup {
492 fn default() -> Self {
493 Self {
494 error_code: 0,
495 error_message: None,
496 group_id: Default::default(),
497 group_state: Default::default(),
498 group_epoch: 0,
499 assignment_epoch: 0,
500 assignor_name: Default::default(),
501 members: Default::default(),
502 authorized_operations: -2147483648,
503 unknown_tagged_fields: BTreeMap::new(),
504 }
505 }
506}
507
508impl Message for DescribedGroup {
509 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
510 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
511}
512
513#[non_exhaustive]
515#[derive(Debug, Clone, PartialEq)]
516pub struct Member {
517 pub member_id: StrBytes,
521
522 pub instance_id: Option<StrBytes>,
526
527 pub rack_id: Option<StrBytes>,
531
532 pub member_epoch: i32,
536
537 pub client_id: StrBytes,
541
542 pub client_host: StrBytes,
546
547 pub subscribed_topic_names: Vec<super::TopicName>,
551
552 pub subscribed_topic_regex: Option<StrBytes>,
556
557 pub assignment: Assignment,
561
562 pub target_assignment: Assignment,
566
567 pub member_type: i8,
571
572 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
574}
575
576impl Member {
577 pub fn with_member_id(mut self, value: StrBytes) -> Self {
583 self.member_id = value;
584 self
585 }
586 pub fn with_instance_id(mut self, value: Option<StrBytes>) -> Self {
592 self.instance_id = value;
593 self
594 }
595 pub fn with_rack_id(mut self, value: Option<StrBytes>) -> Self {
601 self.rack_id = value;
602 self
603 }
604 pub fn with_member_epoch(mut self, value: i32) -> Self {
610 self.member_epoch = value;
611 self
612 }
613 pub fn with_client_id(mut self, value: StrBytes) -> Self {
619 self.client_id = value;
620 self
621 }
622 pub fn with_client_host(mut self, value: StrBytes) -> Self {
628 self.client_host = value;
629 self
630 }
631 pub fn with_subscribed_topic_names(mut self, value: Vec<super::TopicName>) -> Self {
637 self.subscribed_topic_names = value;
638 self
639 }
640 pub fn with_subscribed_topic_regex(mut self, value: Option<StrBytes>) -> Self {
646 self.subscribed_topic_regex = value;
647 self
648 }
649 pub fn with_assignment(mut self, value: Assignment) -> Self {
655 self.assignment = value;
656 self
657 }
658 pub fn with_target_assignment(mut self, value: Assignment) -> Self {
664 self.target_assignment = value;
665 self
666 }
667 pub fn with_member_type(mut self, value: i8) -> Self {
673 self.member_type = value;
674 self
675 }
676 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
678 self.unknown_tagged_fields = value;
679 self
680 }
681 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
683 self.unknown_tagged_fields.insert(key, value);
684 self
685 }
686}
687
688#[cfg(feature = "broker")]
689impl Encodable for Member {
690 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
691 if version < 0 || version > 1 {
692 bail!("specified version not supported by this message type");
693 }
694 types::CompactString.encode(buf, &self.member_id)?;
695 types::CompactString.encode(buf, &self.instance_id)?;
696 types::CompactString.encode(buf, &self.rack_id)?;
697 types::Int32.encode(buf, &self.member_epoch)?;
698 types::CompactString.encode(buf, &self.client_id)?;
699 types::CompactString.encode(buf, &self.client_host)?;
700 types::CompactArray(types::CompactString).encode(buf, &self.subscribed_topic_names)?;
701 types::CompactString.encode(buf, &self.subscribed_topic_regex)?;
702 types::Struct { version }.encode(buf, &self.assignment)?;
703 types::Struct { version }.encode(buf, &self.target_assignment)?;
704 if version >= 1 {
705 types::Int8.encode(buf, &self.member_type)?;
706 }
707 let num_tagged_fields = self.unknown_tagged_fields.len();
708 if num_tagged_fields > std::u32::MAX as usize {
709 bail!(
710 "Too many tagged fields to encode ({} fields)",
711 num_tagged_fields
712 );
713 }
714 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
715
716 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
717 Ok(())
718 }
719 fn compute_size(&self, version: i16) -> Result<usize> {
720 let mut total_size = 0;
721 total_size += types::CompactString.compute_size(&self.member_id)?;
722 total_size += types::CompactString.compute_size(&self.instance_id)?;
723 total_size += types::CompactString.compute_size(&self.rack_id)?;
724 total_size += types::Int32.compute_size(&self.member_epoch)?;
725 total_size += types::CompactString.compute_size(&self.client_id)?;
726 total_size += types::CompactString.compute_size(&self.client_host)?;
727 total_size +=
728 types::CompactArray(types::CompactString).compute_size(&self.subscribed_topic_names)?;
729 total_size += types::CompactString.compute_size(&self.subscribed_topic_regex)?;
730 total_size += types::Struct { version }.compute_size(&self.assignment)?;
731 total_size += types::Struct { version }.compute_size(&self.target_assignment)?;
732 if version >= 1 {
733 total_size += types::Int8.compute_size(&self.member_type)?;
734 }
735 let num_tagged_fields = self.unknown_tagged_fields.len();
736 if num_tagged_fields > std::u32::MAX as usize {
737 bail!(
738 "Too many tagged fields to encode ({} fields)",
739 num_tagged_fields
740 );
741 }
742 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
743
744 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
745 Ok(total_size)
746 }
747}
748
749#[cfg(feature = "client")]
750impl Decodable for Member {
751 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
752 if version < 0 || version > 1 {
753 bail!("specified version not supported by this message type");
754 }
755 let member_id = types::CompactString.decode(buf)?;
756 let instance_id = types::CompactString.decode(buf)?;
757 let rack_id = types::CompactString.decode(buf)?;
758 let member_epoch = types::Int32.decode(buf)?;
759 let client_id = types::CompactString.decode(buf)?;
760 let client_host = types::CompactString.decode(buf)?;
761 let subscribed_topic_names = types::CompactArray(types::CompactString).decode(buf)?;
762 let subscribed_topic_regex = types::CompactString.decode(buf)?;
763 let assignment = types::Struct { version }.decode(buf)?;
764 let target_assignment = types::Struct { version }.decode(buf)?;
765 let member_type = if version >= 1 {
766 types::Int8.decode(buf)?
767 } else {
768 -1
769 };
770 let mut unknown_tagged_fields = BTreeMap::new();
771 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
772 for _ in 0..num_tagged_fields {
773 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
774 let size: u32 = types::UnsignedVarInt.decode(buf)?;
775 let unknown_value = buf.try_get_bytes(size as usize)?;
776 unknown_tagged_fields.insert(tag as i32, unknown_value);
777 }
778 Ok(Self {
779 member_id,
780 instance_id,
781 rack_id,
782 member_epoch,
783 client_id,
784 client_host,
785 subscribed_topic_names,
786 subscribed_topic_regex,
787 assignment,
788 target_assignment,
789 member_type,
790 unknown_tagged_fields,
791 })
792 }
793}
794
795impl Default for Member {
796 fn default() -> Self {
797 Self {
798 member_id: Default::default(),
799 instance_id: None,
800 rack_id: None,
801 member_epoch: 0,
802 client_id: Default::default(),
803 client_host: Default::default(),
804 subscribed_topic_names: Default::default(),
805 subscribed_topic_regex: None,
806 assignment: Default::default(),
807 target_assignment: Default::default(),
808 member_type: -1,
809 unknown_tagged_fields: BTreeMap::new(),
810 }
811 }
812}
813
814impl Message for Member {
815 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
816 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
817}
818
819#[non_exhaustive]
821#[derive(Debug, Clone, PartialEq)]
822pub struct TopicPartitions {
823 pub topic_id: Uuid,
827
828 pub topic_name: super::TopicName,
832
833 pub partitions: Vec<i32>,
837
838 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
840}
841
842impl TopicPartitions {
843 pub fn with_topic_id(mut self, value: Uuid) -> Self {
849 self.topic_id = value;
850 self
851 }
852 pub fn with_topic_name(mut self, value: super::TopicName) -> Self {
858 self.topic_name = value;
859 self
860 }
861 pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
867 self.partitions = value;
868 self
869 }
870 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
872 self.unknown_tagged_fields = value;
873 self
874 }
875 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
877 self.unknown_tagged_fields.insert(key, value);
878 self
879 }
880}
881
882#[cfg(feature = "broker")]
883impl Encodable for TopicPartitions {
884 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
885 if version < 0 || version > 1 {
886 bail!("specified version not supported by this message type");
887 }
888 types::Uuid.encode(buf, &self.topic_id)?;
889 types::CompactString.encode(buf, &self.topic_name)?;
890 types::CompactArray(types::Int32).encode(buf, &self.partitions)?;
891 let num_tagged_fields = self.unknown_tagged_fields.len();
892 if num_tagged_fields > std::u32::MAX as usize {
893 bail!(
894 "Too many tagged fields to encode ({} fields)",
895 num_tagged_fields
896 );
897 }
898 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
899
900 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
901 Ok(())
902 }
903 fn compute_size(&self, version: i16) -> Result<usize> {
904 let mut total_size = 0;
905 total_size += types::Uuid.compute_size(&self.topic_id)?;
906 total_size += types::CompactString.compute_size(&self.topic_name)?;
907 total_size += types::CompactArray(types::Int32).compute_size(&self.partitions)?;
908 let num_tagged_fields = self.unknown_tagged_fields.len();
909 if num_tagged_fields > std::u32::MAX as usize {
910 bail!(
911 "Too many tagged fields to encode ({} fields)",
912 num_tagged_fields
913 );
914 }
915 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
916
917 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
918 Ok(total_size)
919 }
920}
921
922#[cfg(feature = "client")]
923impl Decodable for TopicPartitions {
924 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
925 if version < 0 || version > 1 {
926 bail!("specified version not supported by this message type");
927 }
928 let topic_id = types::Uuid.decode(buf)?;
929 let topic_name = types::CompactString.decode(buf)?;
930 let partitions = types::CompactArray(types::Int32).decode(buf)?;
931 let mut unknown_tagged_fields = BTreeMap::new();
932 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
933 for _ in 0..num_tagged_fields {
934 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
935 let size: u32 = types::UnsignedVarInt.decode(buf)?;
936 let unknown_value = buf.try_get_bytes(size as usize)?;
937 unknown_tagged_fields.insert(tag as i32, unknown_value);
938 }
939 Ok(Self {
940 topic_id,
941 topic_name,
942 partitions,
943 unknown_tagged_fields,
944 })
945 }
946}
947
948impl Default for TopicPartitions {
949 fn default() -> Self {
950 Self {
951 topic_id: Uuid::nil(),
952 topic_name: Default::default(),
953 partitions: Default::default(),
954 unknown_tagged_fields: BTreeMap::new(),
955 }
956 }
957}
958
959impl Message for TopicPartitions {
960 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
961 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
962}
963
964impl HeaderVersion for ConsumerGroupDescribeResponse {
965 fn header_version(version: i16) -> i16 {
966 1
967 }
968}