kafka_protocol/messages/
share_group_describe_response.rs

1//! ShareGroupDescribeResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/ShareGroupDescribeResponse.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: 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: 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: 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 != 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 != 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: 1, max: 1 };
125    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
126}
127
128/// Valid versions: 1
129#[non_exhaustive]
130#[derive(Debug, Clone, PartialEq)]
131pub struct DescribedGroup {
132    /// The describe error, or 0 if there was no error.
133    ///
134    /// Supported API versions: 1
135    pub error_code: i16,
136
137    /// The top-level error message, or null if there was no error.
138    ///
139    /// Supported API versions: 1
140    pub error_message: Option<StrBytes>,
141
142    /// The group ID string.
143    ///
144    /// Supported API versions: 1
145    pub group_id: super::GroupId,
146
147    /// The group state string, or the empty string.
148    ///
149    /// Supported API versions: 1
150    pub group_state: StrBytes,
151
152    /// The group epoch.
153    ///
154    /// Supported API versions: 1
155    pub group_epoch: i32,
156
157    /// The assignment epoch.
158    ///
159    /// Supported API versions: 1
160    pub assignment_epoch: i32,
161
162    /// The selected assignor.
163    ///
164    /// Supported API versions: 1
165    pub assignor_name: StrBytes,
166
167    /// The members.
168    ///
169    /// Supported API versions: 1
170    pub members: Vec<Member>,
171
172    /// 32-bit bitfield to represent authorized operations for this group.
173    ///
174    /// Supported API versions: 1
175    pub authorized_operations: i32,
176
177    /// Other tagged fields
178    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
179}
180
181impl DescribedGroup {
182    /// Sets `error_code` to the passed value.
183    ///
184    /// The describe error, or 0 if there was no error.
185    ///
186    /// Supported API versions: 1
187    pub fn with_error_code(mut self, value: i16) -> Self {
188        self.error_code = value;
189        self
190    }
191    /// Sets `error_message` to the passed value.
192    ///
193    /// The top-level error message, or null if there was no error.
194    ///
195    /// Supported API versions: 1
196    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
197        self.error_message = value;
198        self
199    }
200    /// Sets `group_id` to the passed value.
201    ///
202    /// The group ID string.
203    ///
204    /// Supported API versions: 1
205    pub fn with_group_id(mut self, value: super::GroupId) -> Self {
206        self.group_id = value;
207        self
208    }
209    /// Sets `group_state` to the passed value.
210    ///
211    /// The group state string, or the empty string.
212    ///
213    /// Supported API versions: 1
214    pub fn with_group_state(mut self, value: StrBytes) -> Self {
215        self.group_state = value;
216        self
217    }
218    /// Sets `group_epoch` to the passed value.
219    ///
220    /// The group epoch.
221    ///
222    /// Supported API versions: 1
223    pub fn with_group_epoch(mut self, value: i32) -> Self {
224        self.group_epoch = value;
225        self
226    }
227    /// Sets `assignment_epoch` to the passed value.
228    ///
229    /// The assignment epoch.
230    ///
231    /// Supported API versions: 1
232    pub fn with_assignment_epoch(mut self, value: i32) -> Self {
233        self.assignment_epoch = value;
234        self
235    }
236    /// Sets `assignor_name` to the passed value.
237    ///
238    /// The selected assignor.
239    ///
240    /// Supported API versions: 1
241    pub fn with_assignor_name(mut self, value: StrBytes) -> Self {
242        self.assignor_name = value;
243        self
244    }
245    /// Sets `members` to the passed value.
246    ///
247    /// The members.
248    ///
249    /// Supported API versions: 1
250    pub fn with_members(mut self, value: Vec<Member>) -> Self {
251        self.members = value;
252        self
253    }
254    /// Sets `authorized_operations` to the passed value.
255    ///
256    /// 32-bit bitfield to represent authorized operations for this group.
257    ///
258    /// Supported API versions: 1
259    pub fn with_authorized_operations(mut self, value: i32) -> Self {
260        self.authorized_operations = value;
261        self
262    }
263    /// Sets unknown_tagged_fields to the passed value.
264    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
265        self.unknown_tagged_fields = value;
266        self
267    }
268    /// Inserts an entry into unknown_tagged_fields.
269    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
270        self.unknown_tagged_fields.insert(key, value);
271        self
272    }
273}
274
275#[cfg(feature = "broker")]
276impl Encodable for DescribedGroup {
277    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
278        if version != 1 {
279            bail!("specified version not supported by this message type");
280        }
281        types::Int16.encode(buf, &self.error_code)?;
282        types::CompactString.encode(buf, &self.error_message)?;
283        types::CompactString.encode(buf, &self.group_id)?;
284        types::CompactString.encode(buf, &self.group_state)?;
285        types::Int32.encode(buf, &self.group_epoch)?;
286        types::Int32.encode(buf, &self.assignment_epoch)?;
287        types::CompactString.encode(buf, &self.assignor_name)?;
288        types::CompactArray(types::Struct { version }).encode(buf, &self.members)?;
289        types::Int32.encode(buf, &self.authorized_operations)?;
290        let num_tagged_fields = self.unknown_tagged_fields.len();
291        if num_tagged_fields > std::u32::MAX as usize {
292            bail!(
293                "Too many tagged fields to encode ({} fields)",
294                num_tagged_fields
295            );
296        }
297        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
298
299        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
300        Ok(())
301    }
302    fn compute_size(&self, version: i16) -> Result<usize> {
303        let mut total_size = 0;
304        total_size += types::Int16.compute_size(&self.error_code)?;
305        total_size += types::CompactString.compute_size(&self.error_message)?;
306        total_size += types::CompactString.compute_size(&self.group_id)?;
307        total_size += types::CompactString.compute_size(&self.group_state)?;
308        total_size += types::Int32.compute_size(&self.group_epoch)?;
309        total_size += types::Int32.compute_size(&self.assignment_epoch)?;
310        total_size += types::CompactString.compute_size(&self.assignor_name)?;
311        total_size += types::CompactArray(types::Struct { version }).compute_size(&self.members)?;
312        total_size += types::Int32.compute_size(&self.authorized_operations)?;
313        let num_tagged_fields = self.unknown_tagged_fields.len();
314        if num_tagged_fields > std::u32::MAX as usize {
315            bail!(
316                "Too many tagged fields to encode ({} fields)",
317                num_tagged_fields
318            );
319        }
320        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
321
322        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
323        Ok(total_size)
324    }
325}
326
327#[cfg(feature = "client")]
328impl Decodable for DescribedGroup {
329    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
330        if version != 1 {
331            bail!("specified version not supported by this message type");
332        }
333        let error_code = types::Int16.decode(buf)?;
334        let error_message = types::CompactString.decode(buf)?;
335        let group_id = types::CompactString.decode(buf)?;
336        let group_state = types::CompactString.decode(buf)?;
337        let group_epoch = types::Int32.decode(buf)?;
338        let assignment_epoch = types::Int32.decode(buf)?;
339        let assignor_name = types::CompactString.decode(buf)?;
340        let members = types::CompactArray(types::Struct { version }).decode(buf)?;
341        let authorized_operations = types::Int32.decode(buf)?;
342        let mut unknown_tagged_fields = BTreeMap::new();
343        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
344        for _ in 0..num_tagged_fields {
345            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
346            let size: u32 = types::UnsignedVarInt.decode(buf)?;
347            let unknown_value = buf.try_get_bytes(size as usize)?;
348            unknown_tagged_fields.insert(tag as i32, unknown_value);
349        }
350        Ok(Self {
351            error_code,
352            error_message,
353            group_id,
354            group_state,
355            group_epoch,
356            assignment_epoch,
357            assignor_name,
358            members,
359            authorized_operations,
360            unknown_tagged_fields,
361        })
362    }
363}
364
365impl Default for DescribedGroup {
366    fn default() -> Self {
367        Self {
368            error_code: 0,
369            error_message: None,
370            group_id: Default::default(),
371            group_state: Default::default(),
372            group_epoch: 0,
373            assignment_epoch: 0,
374            assignor_name: Default::default(),
375            members: Default::default(),
376            authorized_operations: -2147483648,
377            unknown_tagged_fields: BTreeMap::new(),
378        }
379    }
380}
381
382impl Message for DescribedGroup {
383    const VERSIONS: VersionRange = VersionRange { min: 1, max: 1 };
384    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
385}
386
387/// Valid versions: 1
388#[non_exhaustive]
389#[derive(Debug, Clone, PartialEq)]
390pub struct Member {
391    /// The member ID.
392    ///
393    /// Supported API versions: 1
394    pub member_id: StrBytes,
395
396    /// The member rack ID.
397    ///
398    /// Supported API versions: 1
399    pub rack_id: Option<StrBytes>,
400
401    /// The current member epoch.
402    ///
403    /// Supported API versions: 1
404    pub member_epoch: i32,
405
406    /// The client ID.
407    ///
408    /// Supported API versions: 1
409    pub client_id: StrBytes,
410
411    /// The client host.
412    ///
413    /// Supported API versions: 1
414    pub client_host: StrBytes,
415
416    /// The subscribed topic names.
417    ///
418    /// Supported API versions: 1
419    pub subscribed_topic_names: Vec<super::TopicName>,
420
421    /// The current assignment.
422    ///
423    /// Supported API versions: 1
424    pub assignment: Assignment,
425
426    /// Other tagged fields
427    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
428}
429
430impl Member {
431    /// Sets `member_id` to the passed value.
432    ///
433    /// The member ID.
434    ///
435    /// Supported API versions: 1
436    pub fn with_member_id(mut self, value: StrBytes) -> Self {
437        self.member_id = value;
438        self
439    }
440    /// Sets `rack_id` to the passed value.
441    ///
442    /// The member rack ID.
443    ///
444    /// Supported API versions: 1
445    pub fn with_rack_id(mut self, value: Option<StrBytes>) -> Self {
446        self.rack_id = value;
447        self
448    }
449    /// Sets `member_epoch` to the passed value.
450    ///
451    /// The current member epoch.
452    ///
453    /// Supported API versions: 1
454    pub fn with_member_epoch(mut self, value: i32) -> Self {
455        self.member_epoch = value;
456        self
457    }
458    /// Sets `client_id` to the passed value.
459    ///
460    /// The client ID.
461    ///
462    /// Supported API versions: 1
463    pub fn with_client_id(mut self, value: StrBytes) -> Self {
464        self.client_id = value;
465        self
466    }
467    /// Sets `client_host` to the passed value.
468    ///
469    /// The client host.
470    ///
471    /// Supported API versions: 1
472    pub fn with_client_host(mut self, value: StrBytes) -> Self {
473        self.client_host = value;
474        self
475    }
476    /// Sets `subscribed_topic_names` to the passed value.
477    ///
478    /// The subscribed topic names.
479    ///
480    /// Supported API versions: 1
481    pub fn with_subscribed_topic_names(mut self, value: Vec<super::TopicName>) -> Self {
482        self.subscribed_topic_names = value;
483        self
484    }
485    /// Sets `assignment` to the passed value.
486    ///
487    /// The current assignment.
488    ///
489    /// Supported API versions: 1
490    pub fn with_assignment(mut self, value: Assignment) -> Self {
491        self.assignment = value;
492        self
493    }
494    /// Sets unknown_tagged_fields to the passed value.
495    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
496        self.unknown_tagged_fields = value;
497        self
498    }
499    /// Inserts an entry into unknown_tagged_fields.
500    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
501        self.unknown_tagged_fields.insert(key, value);
502        self
503    }
504}
505
506#[cfg(feature = "broker")]
507impl Encodable for Member {
508    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
509        if version != 1 {
510            bail!("specified version not supported by this message type");
511        }
512        types::CompactString.encode(buf, &self.member_id)?;
513        types::CompactString.encode(buf, &self.rack_id)?;
514        types::Int32.encode(buf, &self.member_epoch)?;
515        types::CompactString.encode(buf, &self.client_id)?;
516        types::CompactString.encode(buf, &self.client_host)?;
517        types::CompactArray(types::CompactString).encode(buf, &self.subscribed_topic_names)?;
518        types::Struct { version }.encode(buf, &self.assignment)?;
519        let num_tagged_fields = self.unknown_tagged_fields.len();
520        if num_tagged_fields > std::u32::MAX as usize {
521            bail!(
522                "Too many tagged fields to encode ({} fields)",
523                num_tagged_fields
524            );
525        }
526        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
527
528        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
529        Ok(())
530    }
531    fn compute_size(&self, version: i16) -> Result<usize> {
532        let mut total_size = 0;
533        total_size += types::CompactString.compute_size(&self.member_id)?;
534        total_size += types::CompactString.compute_size(&self.rack_id)?;
535        total_size += types::Int32.compute_size(&self.member_epoch)?;
536        total_size += types::CompactString.compute_size(&self.client_id)?;
537        total_size += types::CompactString.compute_size(&self.client_host)?;
538        total_size +=
539            types::CompactArray(types::CompactString).compute_size(&self.subscribed_topic_names)?;
540        total_size += types::Struct { version }.compute_size(&self.assignment)?;
541        let num_tagged_fields = self.unknown_tagged_fields.len();
542        if num_tagged_fields > std::u32::MAX as usize {
543            bail!(
544                "Too many tagged fields to encode ({} fields)",
545                num_tagged_fields
546            );
547        }
548        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
549
550        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
551        Ok(total_size)
552    }
553}
554
555#[cfg(feature = "client")]
556impl Decodable for Member {
557    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
558        if version != 1 {
559            bail!("specified version not supported by this message type");
560        }
561        let member_id = types::CompactString.decode(buf)?;
562        let rack_id = types::CompactString.decode(buf)?;
563        let member_epoch = types::Int32.decode(buf)?;
564        let client_id = types::CompactString.decode(buf)?;
565        let client_host = types::CompactString.decode(buf)?;
566        let subscribed_topic_names = types::CompactArray(types::CompactString).decode(buf)?;
567        let assignment = types::Struct { version }.decode(buf)?;
568        let mut unknown_tagged_fields = BTreeMap::new();
569        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
570        for _ in 0..num_tagged_fields {
571            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
572            let size: u32 = types::UnsignedVarInt.decode(buf)?;
573            let unknown_value = buf.try_get_bytes(size as usize)?;
574            unknown_tagged_fields.insert(tag as i32, unknown_value);
575        }
576        Ok(Self {
577            member_id,
578            rack_id,
579            member_epoch,
580            client_id,
581            client_host,
582            subscribed_topic_names,
583            assignment,
584            unknown_tagged_fields,
585        })
586    }
587}
588
589impl Default for Member {
590    fn default() -> Self {
591        Self {
592            member_id: Default::default(),
593            rack_id: None,
594            member_epoch: 0,
595            client_id: Default::default(),
596            client_host: Default::default(),
597            subscribed_topic_names: Default::default(),
598            assignment: Default::default(),
599            unknown_tagged_fields: BTreeMap::new(),
600        }
601    }
602}
603
604impl Message for Member {
605    const VERSIONS: VersionRange = VersionRange { min: 1, max: 1 };
606    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
607}
608
609/// Valid versions: 1
610#[non_exhaustive]
611#[derive(Debug, Clone, PartialEq)]
612pub struct ShareGroupDescribeResponse {
613    /// 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.
614    ///
615    /// Supported API versions: 1
616    pub throttle_time_ms: i32,
617
618    /// Each described group.
619    ///
620    /// Supported API versions: 1
621    pub groups: Vec<DescribedGroup>,
622
623    /// Other tagged fields
624    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
625}
626
627impl ShareGroupDescribeResponse {
628    /// Sets `throttle_time_ms` to the passed value.
629    ///
630    /// 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.
631    ///
632    /// Supported API versions: 1
633    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
634        self.throttle_time_ms = value;
635        self
636    }
637    /// Sets `groups` to the passed value.
638    ///
639    /// Each described group.
640    ///
641    /// Supported API versions: 1
642    pub fn with_groups(mut self, value: Vec<DescribedGroup>) -> Self {
643        self.groups = value;
644        self
645    }
646    /// Sets unknown_tagged_fields to the passed value.
647    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
648        self.unknown_tagged_fields = value;
649        self
650    }
651    /// Inserts an entry into unknown_tagged_fields.
652    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
653        self.unknown_tagged_fields.insert(key, value);
654        self
655    }
656}
657
658#[cfg(feature = "broker")]
659impl Encodable for ShareGroupDescribeResponse {
660    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
661        if version != 1 {
662            bail!("specified version not supported by this message type");
663        }
664        types::Int32.encode(buf, &self.throttle_time_ms)?;
665        types::CompactArray(types::Struct { version }).encode(buf, &self.groups)?;
666        let num_tagged_fields = self.unknown_tagged_fields.len();
667        if num_tagged_fields > std::u32::MAX as usize {
668            bail!(
669                "Too many tagged fields to encode ({} fields)",
670                num_tagged_fields
671            );
672        }
673        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
674
675        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
676        Ok(())
677    }
678    fn compute_size(&self, version: i16) -> Result<usize> {
679        let mut total_size = 0;
680        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
681        total_size += types::CompactArray(types::Struct { version }).compute_size(&self.groups)?;
682        let num_tagged_fields = self.unknown_tagged_fields.len();
683        if num_tagged_fields > std::u32::MAX as usize {
684            bail!(
685                "Too many tagged fields to encode ({} fields)",
686                num_tagged_fields
687            );
688        }
689        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
690
691        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
692        Ok(total_size)
693    }
694}
695
696#[cfg(feature = "client")]
697impl Decodable for ShareGroupDescribeResponse {
698    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
699        if version != 1 {
700            bail!("specified version not supported by this message type");
701        }
702        let throttle_time_ms = types::Int32.decode(buf)?;
703        let groups = types::CompactArray(types::Struct { version }).decode(buf)?;
704        let mut unknown_tagged_fields = BTreeMap::new();
705        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
706        for _ in 0..num_tagged_fields {
707            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
708            let size: u32 = types::UnsignedVarInt.decode(buf)?;
709            let unknown_value = buf.try_get_bytes(size as usize)?;
710            unknown_tagged_fields.insert(tag as i32, unknown_value);
711        }
712        Ok(Self {
713            throttle_time_ms,
714            groups,
715            unknown_tagged_fields,
716        })
717    }
718}
719
720impl Default for ShareGroupDescribeResponse {
721    fn default() -> Self {
722        Self {
723            throttle_time_ms: 0,
724            groups: Default::default(),
725            unknown_tagged_fields: BTreeMap::new(),
726        }
727    }
728}
729
730impl Message for ShareGroupDescribeResponse {
731    const VERSIONS: VersionRange = VersionRange { min: 1, max: 1 };
732    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
733}
734
735/// Valid versions: 1
736#[non_exhaustive]
737#[derive(Debug, Clone, PartialEq)]
738pub struct TopicPartitions {
739    /// The topic ID.
740    ///
741    /// Supported API versions: 1
742    pub topic_id: Uuid,
743
744    /// The topic name.
745    ///
746    /// Supported API versions: 1
747    pub topic_name: super::TopicName,
748
749    /// The partitions.
750    ///
751    /// Supported API versions: 1
752    pub partitions: Vec<i32>,
753
754    /// Other tagged fields
755    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
756}
757
758impl TopicPartitions {
759    /// Sets `topic_id` to the passed value.
760    ///
761    /// The topic ID.
762    ///
763    /// Supported API versions: 1
764    pub fn with_topic_id(mut self, value: Uuid) -> Self {
765        self.topic_id = value;
766        self
767    }
768    /// Sets `topic_name` to the passed value.
769    ///
770    /// The topic name.
771    ///
772    /// Supported API versions: 1
773    pub fn with_topic_name(mut self, value: super::TopicName) -> Self {
774        self.topic_name = value;
775        self
776    }
777    /// Sets `partitions` to the passed value.
778    ///
779    /// The partitions.
780    ///
781    /// Supported API versions: 1
782    pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
783        self.partitions = value;
784        self
785    }
786    /// Sets unknown_tagged_fields to the passed value.
787    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
788        self.unknown_tagged_fields = value;
789        self
790    }
791    /// Inserts an entry into unknown_tagged_fields.
792    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
793        self.unknown_tagged_fields.insert(key, value);
794        self
795    }
796}
797
798#[cfg(feature = "broker")]
799impl Encodable for TopicPartitions {
800    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
801        if version != 1 {
802            bail!("specified version not supported by this message type");
803        }
804        types::Uuid.encode(buf, &self.topic_id)?;
805        types::CompactString.encode(buf, &self.topic_name)?;
806        types::CompactArray(types::Int32).encode(buf, &self.partitions)?;
807        let num_tagged_fields = self.unknown_tagged_fields.len();
808        if num_tagged_fields > std::u32::MAX as usize {
809            bail!(
810                "Too many tagged fields to encode ({} fields)",
811                num_tagged_fields
812            );
813        }
814        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
815
816        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
817        Ok(())
818    }
819    fn compute_size(&self, version: i16) -> Result<usize> {
820        let mut total_size = 0;
821        total_size += types::Uuid.compute_size(&self.topic_id)?;
822        total_size += types::CompactString.compute_size(&self.topic_name)?;
823        total_size += types::CompactArray(types::Int32).compute_size(&self.partitions)?;
824        let num_tagged_fields = self.unknown_tagged_fields.len();
825        if num_tagged_fields > std::u32::MAX as usize {
826            bail!(
827                "Too many tagged fields to encode ({} fields)",
828                num_tagged_fields
829            );
830        }
831        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
832
833        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
834        Ok(total_size)
835    }
836}
837
838#[cfg(feature = "client")]
839impl Decodable for TopicPartitions {
840    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
841        if version != 1 {
842            bail!("specified version not supported by this message type");
843        }
844        let topic_id = types::Uuid.decode(buf)?;
845        let topic_name = types::CompactString.decode(buf)?;
846        let partitions = types::CompactArray(types::Int32).decode(buf)?;
847        let mut unknown_tagged_fields = BTreeMap::new();
848        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
849        for _ in 0..num_tagged_fields {
850            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
851            let size: u32 = types::UnsignedVarInt.decode(buf)?;
852            let unknown_value = buf.try_get_bytes(size as usize)?;
853            unknown_tagged_fields.insert(tag as i32, unknown_value);
854        }
855        Ok(Self {
856            topic_id,
857            topic_name,
858            partitions,
859            unknown_tagged_fields,
860        })
861    }
862}
863
864impl Default for TopicPartitions {
865    fn default() -> Self {
866        Self {
867            topic_id: Uuid::nil(),
868            topic_name: Default::default(),
869            partitions: Default::default(),
870            unknown_tagged_fields: BTreeMap::new(),
871        }
872    }
873}
874
875impl Message for TopicPartitions {
876    const VERSIONS: VersionRange = VersionRange { min: 1, max: 1 };
877    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
878}
879
880impl HeaderVersion for ShareGroupDescribeResponse {
881    fn header_version(version: i16) -> i16 {
882        1
883    }
884}