Skip to main content

kafka_protocol/messages/
consumer_group_describe_response.rs

1//! ConsumerGroupDescribeResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/ConsumerGroupDescribeResponse.json).
4// WARNING: the items of this module are generated and should not be edited directly
5#![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/// Valid versions: 0-1
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct Assignment {
24    /// The assigned topic-partitions to the member.
25    ///
26    /// Supported API versions: 0-1
27    pub topic_partitions: Vec<TopicPartitions>,
28
29    /// Other tagged fields
30    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
31}
32
33impl Assignment {
34    /// Sets `topic_partitions` to the passed value.
35    ///
36    /// The assigned topic-partitions to the member.
37    ///
38    /// Supported API versions: 0-1
39    pub fn with_topic_partitions(mut self, value: Vec<TopicPartitions>) -> Self {
40        self.topic_partitions = value;
41        self
42    }
43    /// Sets unknown_tagged_fields to the passed value.
44    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
45        self.unknown_tagged_fields = value;
46        self
47    }
48    /// Inserts an entry into unknown_tagged_fields.
49    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/// Valid versions: 0-1
129#[non_exhaustive]
130#[derive(Debug, Clone, PartialEq)]
131pub struct ConsumerGroupDescribeResponse {
132    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
133    ///
134    /// Supported API versions: 0-1
135    pub throttle_time_ms: i32,
136
137    /// Each described group.
138    ///
139    /// Supported API versions: 0-1
140    pub groups: Vec<DescribedGroup>,
141
142    /// Other tagged fields
143    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
144}
145
146impl ConsumerGroupDescribeResponse {
147    /// Sets `throttle_time_ms` to the passed value.
148    ///
149    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
150    ///
151    /// Supported API versions: 0-1
152    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
153        self.throttle_time_ms = value;
154        self
155    }
156    /// Sets `groups` to the passed value.
157    ///
158    /// Each described group.
159    ///
160    /// Supported API versions: 0-1
161    pub fn with_groups(mut self, value: Vec<DescribedGroup>) -> Self {
162        self.groups = value;
163        self
164    }
165    /// Sets unknown_tagged_fields to the passed value.
166    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
167        self.unknown_tagged_fields = value;
168        self
169    }
170    /// Inserts an entry into unknown_tagged_fields.
171    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/// Valid versions: 0-1
255#[non_exhaustive]
256#[derive(Debug, Clone, PartialEq)]
257pub struct DescribedGroup {
258    /// The describe error, or 0 if there was no error.
259    ///
260    /// Supported API versions: 0-1
261    pub error_code: i16,
262
263    /// The top-level error message, or null if there was no error.
264    ///
265    /// Supported API versions: 0-1
266    pub error_message: Option<StrBytes>,
267
268    /// The group ID string.
269    ///
270    /// Supported API versions: 0-1
271    pub group_id: super::GroupId,
272
273    /// The group state string, or the empty string.
274    ///
275    /// Supported API versions: 0-1
276    pub group_state: StrBytes,
277
278    /// The group epoch.
279    ///
280    /// Supported API versions: 0-1
281    pub group_epoch: i32,
282
283    /// The assignment epoch.
284    ///
285    /// Supported API versions: 0-1
286    pub assignment_epoch: i32,
287
288    /// The selected assignor.
289    ///
290    /// Supported API versions: 0-1
291    pub assignor_name: StrBytes,
292
293    /// The members.
294    ///
295    /// Supported API versions: 0-1
296    pub members: Vec<Member>,
297
298    /// 32-bit bitfield to represent authorized operations for this group.
299    ///
300    /// Supported API versions: 0-1
301    pub authorized_operations: i32,
302
303    /// Other tagged fields
304    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
305}
306
307impl DescribedGroup {
308    /// Sets `error_code` to the passed value.
309    ///
310    /// The describe error, or 0 if there was no error.
311    ///
312    /// Supported API versions: 0-1
313    pub fn with_error_code(mut self, value: i16) -> Self {
314        self.error_code = value;
315        self
316    }
317    /// Sets `error_message` to the passed value.
318    ///
319    /// The top-level error message, or null if there was no error.
320    ///
321    /// Supported API versions: 0-1
322    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
323        self.error_message = value;
324        self
325    }
326    /// Sets `group_id` to the passed value.
327    ///
328    /// The group ID string.
329    ///
330    /// Supported API versions: 0-1
331    pub fn with_group_id(mut self, value: super::GroupId) -> Self {
332        self.group_id = value;
333        self
334    }
335    /// Sets `group_state` to the passed value.
336    ///
337    /// The group state string, or the empty string.
338    ///
339    /// Supported API versions: 0-1
340    pub fn with_group_state(mut self, value: StrBytes) -> Self {
341        self.group_state = value;
342        self
343    }
344    /// Sets `group_epoch` to the passed value.
345    ///
346    /// The group epoch.
347    ///
348    /// Supported API versions: 0-1
349    pub fn with_group_epoch(mut self, value: i32) -> Self {
350        self.group_epoch = value;
351        self
352    }
353    /// Sets `assignment_epoch` to the passed value.
354    ///
355    /// The assignment epoch.
356    ///
357    /// Supported API versions: 0-1
358    pub fn with_assignment_epoch(mut self, value: i32) -> Self {
359        self.assignment_epoch = value;
360        self
361    }
362    /// Sets `assignor_name` to the passed value.
363    ///
364    /// The selected assignor.
365    ///
366    /// Supported API versions: 0-1
367    pub fn with_assignor_name(mut self, value: StrBytes) -> Self {
368        self.assignor_name = value;
369        self
370    }
371    /// Sets `members` to the passed value.
372    ///
373    /// The members.
374    ///
375    /// Supported API versions: 0-1
376    pub fn with_members(mut self, value: Vec<Member>) -> Self {
377        self.members = value;
378        self
379    }
380    /// Sets `authorized_operations` to the passed value.
381    ///
382    /// 32-bit bitfield to represent authorized operations for this group.
383    ///
384    /// Supported API versions: 0-1
385    pub fn with_authorized_operations(mut self, value: i32) -> Self {
386        self.authorized_operations = value;
387        self
388    }
389    /// Sets unknown_tagged_fields to the passed value.
390    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
391        self.unknown_tagged_fields = value;
392        self
393    }
394    /// Inserts an entry into unknown_tagged_fields.
395    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/// Valid versions: 0-1
514#[non_exhaustive]
515#[derive(Debug, Clone, PartialEq)]
516pub struct Member {
517    /// The member ID.
518    ///
519    /// Supported API versions: 0-1
520    pub member_id: StrBytes,
521
522    /// The member instance ID.
523    ///
524    /// Supported API versions: 0-1
525    pub instance_id: Option<StrBytes>,
526
527    /// The member rack ID.
528    ///
529    /// Supported API versions: 0-1
530    pub rack_id: Option<StrBytes>,
531
532    /// The current member epoch.
533    ///
534    /// Supported API versions: 0-1
535    pub member_epoch: i32,
536
537    /// The client ID.
538    ///
539    /// Supported API versions: 0-1
540    pub client_id: StrBytes,
541
542    /// The client host.
543    ///
544    /// Supported API versions: 0-1
545    pub client_host: StrBytes,
546
547    /// The subscribed topic names.
548    ///
549    /// Supported API versions: 0-1
550    pub subscribed_topic_names: Vec<super::TopicName>,
551
552    /// the subscribed topic regex otherwise or null of not provided.
553    ///
554    /// Supported API versions: 0-1
555    pub subscribed_topic_regex: Option<StrBytes>,
556
557    /// The current assignment.
558    ///
559    /// Supported API versions: 0-1
560    pub assignment: Assignment,
561
562    /// The target assignment.
563    ///
564    /// Supported API versions: 0-1
565    pub target_assignment: Assignment,
566
567    /// -1 for unknown. 0 for classic member. +1 for consumer member.
568    ///
569    /// Supported API versions: 1
570    pub member_type: i8,
571
572    /// Other tagged fields
573    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
574}
575
576impl Member {
577    /// Sets `member_id` to the passed value.
578    ///
579    /// The member ID.
580    ///
581    /// Supported API versions: 0-1
582    pub fn with_member_id(mut self, value: StrBytes) -> Self {
583        self.member_id = value;
584        self
585    }
586    /// Sets `instance_id` to the passed value.
587    ///
588    /// The member instance ID.
589    ///
590    /// Supported API versions: 0-1
591    pub fn with_instance_id(mut self, value: Option<StrBytes>) -> Self {
592        self.instance_id = value;
593        self
594    }
595    /// Sets `rack_id` to the passed value.
596    ///
597    /// The member rack ID.
598    ///
599    /// Supported API versions: 0-1
600    pub fn with_rack_id(mut self, value: Option<StrBytes>) -> Self {
601        self.rack_id = value;
602        self
603    }
604    /// Sets `member_epoch` to the passed value.
605    ///
606    /// The current member epoch.
607    ///
608    /// Supported API versions: 0-1
609    pub fn with_member_epoch(mut self, value: i32) -> Self {
610        self.member_epoch = value;
611        self
612    }
613    /// Sets `client_id` to the passed value.
614    ///
615    /// The client ID.
616    ///
617    /// Supported API versions: 0-1
618    pub fn with_client_id(mut self, value: StrBytes) -> Self {
619        self.client_id = value;
620        self
621    }
622    /// Sets `client_host` to the passed value.
623    ///
624    /// The client host.
625    ///
626    /// Supported API versions: 0-1
627    pub fn with_client_host(mut self, value: StrBytes) -> Self {
628        self.client_host = value;
629        self
630    }
631    /// Sets `subscribed_topic_names` to the passed value.
632    ///
633    /// The subscribed topic names.
634    ///
635    /// Supported API versions: 0-1
636    pub fn with_subscribed_topic_names(mut self, value: Vec<super::TopicName>) -> Self {
637        self.subscribed_topic_names = value;
638        self
639    }
640    /// Sets `subscribed_topic_regex` to the passed value.
641    ///
642    /// the subscribed topic regex otherwise or null of not provided.
643    ///
644    /// Supported API versions: 0-1
645    pub fn with_subscribed_topic_regex(mut self, value: Option<StrBytes>) -> Self {
646        self.subscribed_topic_regex = value;
647        self
648    }
649    /// Sets `assignment` to the passed value.
650    ///
651    /// The current assignment.
652    ///
653    /// Supported API versions: 0-1
654    pub fn with_assignment(mut self, value: Assignment) -> Self {
655        self.assignment = value;
656        self
657    }
658    /// Sets `target_assignment` to the passed value.
659    ///
660    /// The target assignment.
661    ///
662    /// Supported API versions: 0-1
663    pub fn with_target_assignment(mut self, value: Assignment) -> Self {
664        self.target_assignment = value;
665        self
666    }
667    /// Sets `member_type` to the passed value.
668    ///
669    /// -1 for unknown. 0 for classic member. +1 for consumer member.
670    ///
671    /// Supported API versions: 1
672    pub fn with_member_type(mut self, value: i8) -> Self {
673        self.member_type = value;
674        self
675    }
676    /// Sets unknown_tagged_fields to the passed value.
677    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
678        self.unknown_tagged_fields = value;
679        self
680    }
681    /// Inserts an entry into unknown_tagged_fields.
682    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/// Valid versions: 0-1
820#[non_exhaustive]
821#[derive(Debug, Clone, PartialEq)]
822pub struct TopicPartitions {
823    /// The topic ID.
824    ///
825    /// Supported API versions: 0-1
826    pub topic_id: Uuid,
827
828    /// The topic name.
829    ///
830    /// Supported API versions: 0-1
831    pub topic_name: super::TopicName,
832
833    /// The partitions.
834    ///
835    /// Supported API versions: 0-1
836    pub partitions: Vec<i32>,
837
838    /// Other tagged fields
839    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
840}
841
842impl TopicPartitions {
843    /// Sets `topic_id` to the passed value.
844    ///
845    /// The topic ID.
846    ///
847    /// Supported API versions: 0-1
848    pub fn with_topic_id(mut self, value: Uuid) -> Self {
849        self.topic_id = value;
850        self
851    }
852    /// Sets `topic_name` to the passed value.
853    ///
854    /// The topic name.
855    ///
856    /// Supported API versions: 0-1
857    pub fn with_topic_name(mut self, value: super::TopicName) -> Self {
858        self.topic_name = value;
859        self
860    }
861    /// Sets `partitions` to the passed value.
862    ///
863    /// The partitions.
864    ///
865    /// Supported API versions: 0-1
866    pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
867        self.partitions = value;
868        self
869    }
870    /// Sets unknown_tagged_fields to the passed value.
871    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
872        self.unknown_tagged_fields = value;
873        self
874    }
875    /// Inserts an entry into unknown_tagged_fields.
876    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}