Skip to main content

odradek_protocol/messages/
list_groups_response.rs

1//! `ListGroupsResponse` — generated from `schemas/ListGroupsResponse.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 >= 3
25}
26
27/// `ListGroupsResponse`, versions 0-5.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct ListGroupsResponse {
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    /// The error code, or 0 if there was no error.
34    pub error_code: i16,
35    /// Each group in the response.
36    pub groups: Vec<ListedGroup>,
37    /// Tagged fields not (yet) known to this crate, kept raw.
38    pub unknown_tagged_fields: Vec<RawTaggedField>,
39}
40
41impl Default for ListGroupsResponse {
42    fn default() -> Self {
43        Self {
44            throttle_time_ms: 0,
45            error_code: 0,
46            groups: Vec::new(),
47            unknown_tagged_fields: Vec::new(),
48        }
49    }
50}
51
52impl ListGroupsResponse {
53    /// This message's api key in Kafka's registry.
54    pub const API_KEY: i16 = 16;
55    /// The lowest schema version this snapshot can speak.
56    pub const MIN_VERSION: i16 = 0;
57    /// The highest schema version this snapshot can speak.
58    pub const MAX_VERSION: i16 = 5;
59
60    /// Encode this `ListGroupsResponse` at `version`.
61    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
62        if version >= 1 {
63            buf.put_i32(self.throttle_time_ms);
64        }
65        buf.put_i16(self.error_code);
66        if is_flexible(version) {
67            wire::put_compact_array_len(buf, Some(self.groups.len()));
68        } else {
69            wire::put_array_len(buf, Some(self.groups.len()))?;
70        }
71        for item in &self.groups {
72            item.encode(buf, version)?;
73        }
74        if is_flexible(version) {
75            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
76        }
77        Ok(())
78    }
79
80    /// Decode one `ListGroupsResponse`, bounding allocation by the default
81    /// [`Limits`] derived from `buf`'s remaining length.
82    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
83        Self::decode_with_limits(buf, version, Limits::default())
84    }
85
86    /// Decode one `ListGroupsResponse` under `limits`.
87    pub fn decode_with_limits(
88        buf: &mut impl Buf,
89        version: i16,
90        limits: Limits,
91    ) -> Result<Self, DecodeError> {
92        let mut budget = limits.budget(buf.remaining());
93        Self::decode_with_budget(buf, version, &mut budget)
94    }
95
96    /// Decode one `ListGroupsResponse` against an existing `budget`.
97    pub fn decode_with_budget(
98        buf: &mut impl Buf,
99        version: i16,
100        budget: &mut Budget,
101    ) -> Result<Self, DecodeError> {
102        let mut this = Self::default();
103        if version >= 1 {
104            this.throttle_time_ms = wire::get_i32(buf)?;
105        }
106        this.error_code = wire::get_i16(buf)?;
107        this.groups = {
108            let len = if is_flexible(version) {
109                wire::get_compact_array_len(buf)?
110            } else {
111                wire::get_array_len(buf)?
112            };
113            match len {
114                None => return Err(DecodeError::InvalidLength(-1)),
115                Some(n) => {
116                    let mut items = Vec::new();
117                    for _ in 0..n {
118                        let mark = buf.remaining();
119                        let item = ListedGroup::decode_with_budget(buf, version, budget)?;
120                        budget.progress(mark, buf.remaining())?;
121                        budget.push(&mut items, item)?;
122                    }
123                    items
124                }
125            }
126        };
127        if is_flexible(version) {
128            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
129        }
130        Ok(this)
131    }
132}
133
134impl crate::Message for ListGroupsResponse {
135    const API_KEY: i16 = 16;
136    const MIN_VERSION: i16 = 0;
137    const MAX_VERSION: i16 = 5;
138
139    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
140        ListGroupsResponse::encode(self, buf, version)
141    }
142    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
143        ListGroupsResponse::decode(buf, version)
144    }
145    fn decode_with_limits(
146        buf: &mut impl Buf,
147        version: i16,
148        limits: Limits,
149    ) -> Result<Self, DecodeError> {
150        ListGroupsResponse::decode_with_limits(buf, version, limits)
151    }
152    fn throttle_time_ms(&self) -> Option<i32> {
153        Some(self.throttle_time_ms)
154    }
155}
156
157/// `ListedGroup` (nested in [`ListGroupsResponse`]).
158#[derive(Debug, Clone, PartialEq)]
159#[non_exhaustive]
160pub struct ListedGroup {
161    /// The group ID.
162    pub group_id: String,
163    /// The group protocol type.
164    pub protocol_type: String,
165    /// The group state name.
166    pub group_state: String,
167    /// The group type name.
168    pub group_type: String,
169    /// Tagged fields not (yet) known to this crate, kept raw.
170    pub unknown_tagged_fields: Vec<RawTaggedField>,
171}
172
173impl Default for ListedGroup {
174    fn default() -> Self {
175        Self {
176            group_id: String::new(),
177            protocol_type: String::new(),
178            group_state: String::new(),
179            group_type: String::new(),
180            unknown_tagged_fields: Vec::new(),
181        }
182    }
183}
184
185impl ListedGroup {
186    /// Encode this `ListedGroup` at `version`.
187    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
188        if is_flexible(version) {
189            wire::put_compact_string(buf, &self.group_id);
190        } else {
191            wire::put_string(buf, &self.group_id)?;
192        }
193        if is_flexible(version) {
194            wire::put_compact_string(buf, &self.protocol_type);
195        } else {
196            wire::put_string(buf, &self.protocol_type)?;
197        }
198        if version >= 4 {
199            if is_flexible(version) {
200                wire::put_compact_string(buf, &self.group_state);
201            } else {
202                wire::put_string(buf, &self.group_state)?;
203            }
204        }
205        if version >= 5 {
206            if is_flexible(version) {
207                wire::put_compact_string(buf, &self.group_type);
208            } else {
209                wire::put_string(buf, &self.group_type)?;
210            }
211        }
212        if is_flexible(version) {
213            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
214        }
215        Ok(())
216    }
217
218    /// Decode one `ListedGroup`, bounding allocation by the default
219    /// [`Limits`] derived from `buf`'s remaining length.
220    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
221        Self::decode_with_limits(buf, version, Limits::default())
222    }
223
224    /// Decode one `ListedGroup` under `limits`.
225    pub fn decode_with_limits(
226        buf: &mut impl Buf,
227        version: i16,
228        limits: Limits,
229    ) -> Result<Self, DecodeError> {
230        let mut budget = limits.budget(buf.remaining());
231        Self::decode_with_budget(buf, version, &mut budget)
232    }
233
234    /// Decode one `ListedGroup` against an existing `budget`.
235    pub fn decode_with_budget(
236        buf: &mut impl Buf,
237        version: i16,
238        budget: &mut Budget,
239    ) -> Result<Self, DecodeError> {
240        let mut this = Self::default();
241        this.group_id = if is_flexible(version) {
242            wire::get_compact_string(buf)?
243        } else {
244            wire::get_string(buf)?
245        };
246        this.protocol_type = if is_flexible(version) {
247            wire::get_compact_string(buf)?
248        } else {
249            wire::get_string(buf)?
250        };
251        if version >= 4 {
252            this.group_state = if is_flexible(version) {
253                wire::get_compact_string(buf)?
254            } else {
255                wire::get_string(buf)?
256            };
257        }
258        if version >= 5 {
259            this.group_type = if is_flexible(version) {
260                wire::get_compact_string(buf)?
261            } else {
262                wire::get_string(buf)?
263            };
264        }
265        if is_flexible(version) {
266            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
267        }
268        Ok(this)
269    }
270}