Skip to main content

odradek_protocol/messages/
describe_groups_response.rs

1//! `DescribeGroupsResponse` — generated from `schemas/DescribeGroupsResponse.json`.
2//!
3//! @generated by `cargo xtask codegen`. Do not edit by hand.
4
5#![allow(
6    clippy::field_reassign_with_default,
7    clippy::nonminimal_bool,
8    clippy::derivable_impls,
9    clippy::borrow_deref_ref,
10    clippy::double_parens,
11    unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21/// Whether `version` of this message uses the flexible (compact) encoding.
22pub fn is_flexible(version: i16) -> bool {
23    let _ = version;
24    version >= 5
25}
26
27/// `DescribeGroupsResponse`, versions 0-6.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct DescribeGroupsResponse {
31    /// 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.
32    pub throttle_time_ms: i32,
33    /// Each described group.
34    pub groups: Vec<DescribedGroup>,
35    /// Tagged fields not (yet) known to this crate, kept raw.
36    pub unknown_tagged_fields: Vec<RawTaggedField>,
37}
38
39impl Default for DescribeGroupsResponse {
40    fn default() -> Self {
41        Self {
42            throttle_time_ms: 0,
43            groups: Vec::new(),
44            unknown_tagged_fields: Vec::new(),
45        }
46    }
47}
48
49impl DescribeGroupsResponse {
50    /// This message's api key in Kafka's registry.
51    pub const API_KEY: i16 = 15;
52    /// The lowest schema version this snapshot can speak.
53    pub const MIN_VERSION: i16 = 0;
54    /// The highest schema version this snapshot can speak.
55    pub const MAX_VERSION: i16 = 6;
56
57    /// Encode this `DescribeGroupsResponse` at `version`.
58    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
59        if version >= 1 {
60            buf.put_i32(self.throttle_time_ms);
61        }
62        if is_flexible(version) {
63            wire::put_compact_array_len(buf, Some(self.groups.len()));
64        } else {
65            wire::put_array_len(buf, Some(self.groups.len()))?;
66        }
67        for item in &self.groups {
68            item.encode(buf, version)?;
69        }
70        if is_flexible(version) {
71            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
72        }
73        Ok(())
74    }
75
76    /// Decode one `DescribeGroupsResponse`, bounding allocation by the default
77    /// [`Limits`] derived from `buf`'s remaining length.
78    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
79        Self::decode_with_limits(buf, version, Limits::default())
80    }
81
82    /// Decode one `DescribeGroupsResponse` under `limits`.
83    pub fn decode_with_limits(
84        buf: &mut impl Buf,
85        version: i16,
86        limits: Limits,
87    ) -> Result<Self, DecodeError> {
88        let mut budget = limits.budget(buf.remaining());
89        Self::decode_with_budget(buf, version, &mut budget)
90    }
91
92    /// Decode one `DescribeGroupsResponse` against an existing `budget`.
93    pub fn decode_with_budget(
94        buf: &mut impl Buf,
95        version: i16,
96        budget: &mut Budget,
97    ) -> Result<Self, DecodeError> {
98        let mut this = Self::default();
99        if version >= 1 {
100            this.throttle_time_ms = wire::get_i32(buf)?;
101        }
102        this.groups = {
103            let len = if is_flexible(version) {
104                wire::get_compact_array_len(buf)?
105            } else {
106                wire::get_array_len(buf)?
107            };
108            match len {
109                None => return Err(DecodeError::InvalidLength(-1)),
110                Some(n) => {
111                    let mut items = Vec::new();
112                    for _ in 0..n {
113                        let mark = buf.remaining();
114                        let item = DescribedGroup::decode_with_budget(buf, version, budget)?;
115                        budget.progress(mark, buf.remaining())?;
116                        budget.push(&mut items, item)?;
117                    }
118                    items
119                }
120            }
121        };
122        if is_flexible(version) {
123            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
124        }
125        Ok(this)
126    }
127}
128
129impl crate::Message for DescribeGroupsResponse {
130    const API_KEY: i16 = 15;
131    const MIN_VERSION: i16 = 0;
132    const MAX_VERSION: i16 = 6;
133
134    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
135        DescribeGroupsResponse::encode(self, buf, version)
136    }
137    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
138        DescribeGroupsResponse::decode(buf, version)
139    }
140    fn decode_with_limits(
141        buf: &mut impl Buf,
142        version: i16,
143        limits: Limits,
144    ) -> Result<Self, DecodeError> {
145        DescribeGroupsResponse::decode_with_limits(buf, version, limits)
146    }
147    fn throttle_time_ms(&self) -> Option<i32> {
148        Some(self.throttle_time_ms)
149    }
150}
151
152/// `DescribedGroup` (nested in [`DescribeGroupsResponse`]).
153#[derive(Debug, Clone, PartialEq)]
154#[non_exhaustive]
155pub struct DescribedGroup {
156    /// The describe error, or 0 if there was no error.
157    pub error_code: i16,
158    /// The describe error message, or null if there was no error.
159    pub error_message: Option<String>,
160    /// The group ID string.
161    pub group_id: String,
162    /// The group state string, or the empty string.
163    pub group_state: String,
164    /// The group protocol type, or the empty string.
165    pub protocol_type: String,
166    /// The group protocol data, or the empty string.
167    pub protocol_data: String,
168    /// The group members.
169    pub members: Vec<DescribedGroupMember>,
170    /// 32-bit bitfield to represent authorized operations for this group.
171    pub authorized_operations: i32,
172    /// Tagged fields not (yet) known to this crate, kept raw.
173    pub unknown_tagged_fields: Vec<RawTaggedField>,
174}
175
176impl Default for DescribedGroup {
177    fn default() -> Self {
178        Self {
179            error_code: 0,
180            error_message: None,
181            group_id: String::new(),
182            group_state: String::new(),
183            protocol_type: String::new(),
184            protocol_data: String::new(),
185            members: Vec::new(),
186            authorized_operations: -2147483648,
187            unknown_tagged_fields: Vec::new(),
188        }
189    }
190}
191
192impl DescribedGroup {
193    /// Encode this `DescribedGroup` at `version`.
194    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
195        buf.put_i16(self.error_code);
196        if version >= 6 {
197            if is_flexible(version) {
198                wire::put_compact_nullable_string(buf, self.error_message.as_deref());
199            } else {
200                wire::put_nullable_string(buf, self.error_message.as_deref())?;
201            }
202        }
203        if is_flexible(version) {
204            wire::put_compact_string(buf, &self.group_id);
205        } else {
206            wire::put_string(buf, &self.group_id)?;
207        }
208        if is_flexible(version) {
209            wire::put_compact_string(buf, &self.group_state);
210        } else {
211            wire::put_string(buf, &self.group_state)?;
212        }
213        if is_flexible(version) {
214            wire::put_compact_string(buf, &self.protocol_type);
215        } else {
216            wire::put_string(buf, &self.protocol_type)?;
217        }
218        if is_flexible(version) {
219            wire::put_compact_string(buf, &self.protocol_data);
220        } else {
221            wire::put_string(buf, &self.protocol_data)?;
222        }
223        if is_flexible(version) {
224            wire::put_compact_array_len(buf, Some(self.members.len()));
225        } else {
226            wire::put_array_len(buf, Some(self.members.len()))?;
227        }
228        for item in &self.members {
229            item.encode(buf, version)?;
230        }
231        if version >= 3 {
232            buf.put_i32(self.authorized_operations);
233        }
234        if is_flexible(version) {
235            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
236        }
237        Ok(())
238    }
239
240    /// Decode one `DescribedGroup`, bounding allocation by the default
241    /// [`Limits`] derived from `buf`'s remaining length.
242    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
243        Self::decode_with_limits(buf, version, Limits::default())
244    }
245
246    /// Decode one `DescribedGroup` under `limits`.
247    pub fn decode_with_limits(
248        buf: &mut impl Buf,
249        version: i16,
250        limits: Limits,
251    ) -> Result<Self, DecodeError> {
252        let mut budget = limits.budget(buf.remaining());
253        Self::decode_with_budget(buf, version, &mut budget)
254    }
255
256    /// Decode one `DescribedGroup` against an existing `budget`.
257    pub fn decode_with_budget(
258        buf: &mut impl Buf,
259        version: i16,
260        budget: &mut Budget,
261    ) -> Result<Self, DecodeError> {
262        let mut this = Self::default();
263        this.error_code = wire::get_i16(buf)?;
264        if version >= 6 {
265            this.error_message = if is_flexible(version) {
266                wire::get_compact_nullable_string(buf)?
267            } else {
268                wire::get_nullable_string(buf)?
269            };
270        }
271        this.group_id = if is_flexible(version) {
272            wire::get_compact_string(buf)?
273        } else {
274            wire::get_string(buf)?
275        };
276        this.group_state = if is_flexible(version) {
277            wire::get_compact_string(buf)?
278        } else {
279            wire::get_string(buf)?
280        };
281        this.protocol_type = if is_flexible(version) {
282            wire::get_compact_string(buf)?
283        } else {
284            wire::get_string(buf)?
285        };
286        this.protocol_data = if is_flexible(version) {
287            wire::get_compact_string(buf)?
288        } else {
289            wire::get_string(buf)?
290        };
291        this.members = {
292            let len = if is_flexible(version) {
293                wire::get_compact_array_len(buf)?
294            } else {
295                wire::get_array_len(buf)?
296            };
297            match len {
298                None => return Err(DecodeError::InvalidLength(-1)),
299                Some(n) => {
300                    let mut items = Vec::new();
301                    for _ in 0..n {
302                        let mark = buf.remaining();
303                        let item = DescribedGroupMember::decode_with_budget(buf, version, budget)?;
304                        budget.progress(mark, buf.remaining())?;
305                        budget.push(&mut items, item)?;
306                    }
307                    items
308                }
309            }
310        };
311        if version >= 3 {
312            this.authorized_operations = wire::get_i32(buf)?;
313        }
314        if is_flexible(version) {
315            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
316        }
317        Ok(this)
318    }
319}
320
321/// `DescribedGroupMember` (nested in [`DescribeGroupsResponse`]).
322#[derive(Debug, Clone, PartialEq)]
323#[non_exhaustive]
324pub struct DescribedGroupMember {
325    /// The member id.
326    pub member_id: String,
327    /// The unique identifier of the consumer instance provided by end user.
328    pub group_instance_id: Option<String>,
329    /// The client ID used in the member's latest join group request.
330    pub client_id: String,
331    /// The client host.
332    pub client_host: String,
333    /// The metadata corresponding to the current group protocol in use.
334    pub member_metadata: bytes::Bytes,
335    /// The current assignment provided by the group leader.
336    pub member_assignment: bytes::Bytes,
337    /// Tagged fields not (yet) known to this crate, kept raw.
338    pub unknown_tagged_fields: Vec<RawTaggedField>,
339}
340
341impl Default for DescribedGroupMember {
342    fn default() -> Self {
343        Self {
344            member_id: String::new(),
345            group_instance_id: None,
346            client_id: String::new(),
347            client_host: String::new(),
348            member_metadata: bytes::Bytes::new(),
349            member_assignment: bytes::Bytes::new(),
350            unknown_tagged_fields: Vec::new(),
351        }
352    }
353}
354
355impl DescribedGroupMember {
356    /// Encode this `DescribedGroupMember` at `version`.
357    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
358        if is_flexible(version) {
359            wire::put_compact_string(buf, &self.member_id);
360        } else {
361            wire::put_string(buf, &self.member_id)?;
362        }
363        if version >= 4 {
364            if is_flexible(version) {
365                wire::put_compact_nullable_string(buf, self.group_instance_id.as_deref());
366            } else {
367                wire::put_nullable_string(buf, self.group_instance_id.as_deref())?;
368            }
369        }
370        if is_flexible(version) {
371            wire::put_compact_string(buf, &self.client_id);
372        } else {
373            wire::put_string(buf, &self.client_id)?;
374        }
375        if is_flexible(version) {
376            wire::put_compact_string(buf, &self.client_host);
377        } else {
378            wire::put_string(buf, &self.client_host)?;
379        }
380        if is_flexible(version) {
381            wire::put_compact_bytes(buf, &self.member_metadata);
382        } else {
383            wire::put_bytes(buf, &self.member_metadata)?;
384        }
385        if is_flexible(version) {
386            wire::put_compact_bytes(buf, &self.member_assignment);
387        } else {
388            wire::put_bytes(buf, &self.member_assignment)?;
389        }
390        if is_flexible(version) {
391            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
392        }
393        Ok(())
394    }
395
396    /// Decode one `DescribedGroupMember`, bounding allocation by the default
397    /// [`Limits`] derived from `buf`'s remaining length.
398    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
399        Self::decode_with_limits(buf, version, Limits::default())
400    }
401
402    /// Decode one `DescribedGroupMember` under `limits`.
403    pub fn decode_with_limits(
404        buf: &mut impl Buf,
405        version: i16,
406        limits: Limits,
407    ) -> Result<Self, DecodeError> {
408        let mut budget = limits.budget(buf.remaining());
409        Self::decode_with_budget(buf, version, &mut budget)
410    }
411
412    /// Decode one `DescribedGroupMember` against an existing `budget`.
413    pub fn decode_with_budget(
414        buf: &mut impl Buf,
415        version: i16,
416        budget: &mut Budget,
417    ) -> Result<Self, DecodeError> {
418        let mut this = Self::default();
419        this.member_id = if is_flexible(version) {
420            wire::get_compact_string(buf)?
421        } else {
422            wire::get_string(buf)?
423        };
424        if version >= 4 {
425            this.group_instance_id = if is_flexible(version) {
426                wire::get_compact_nullable_string(buf)?
427            } else {
428                wire::get_nullable_string(buf)?
429            };
430        }
431        this.client_id = if is_flexible(version) {
432            wire::get_compact_string(buf)?
433        } else {
434            wire::get_string(buf)?
435        };
436        this.client_host = if is_flexible(version) {
437            wire::get_compact_string(buf)?
438        } else {
439            wire::get_string(buf)?
440        };
441        this.member_metadata = {
442            let raw = if is_flexible(version) {
443                wire::get_compact_nullable_bytes(buf)?
444            } else {
445                wire::get_nullable_bytes(buf)?
446            };
447            match raw {
448                Some(v) => v,
449                None => return Err(DecodeError::InvalidLength(-1)),
450            }
451        };
452        this.member_assignment = {
453            let raw = if is_flexible(version) {
454                wire::get_compact_nullable_bytes(buf)?
455            } else {
456                wire::get_nullable_bytes(buf)?
457            };
458            match raw {
459                Some(v) => v,
460                None => return Err(DecodeError::InvalidLength(-1)),
461            }
462        };
463        if is_flexible(version) {
464            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
465        }
466        Ok(this)
467    }
468}