kafka_protocol/messages/
list_groups_response.rs

1//! ListGroupsResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/ListGroupsResponse.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-5
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct ListGroupsResponse {
24    /// 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.
25    ///
26    /// Supported API versions: 1-5
27    pub throttle_time_ms: i32,
28
29    /// The error code, or 0 if there was no error.
30    ///
31    /// Supported API versions: 0-5
32    pub error_code: i16,
33
34    /// Each group in the response.
35    ///
36    /// Supported API versions: 0-5
37    pub groups: Vec<ListedGroup>,
38
39    /// Other tagged fields
40    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl ListGroupsResponse {
44    /// Sets `throttle_time_ms` to the passed value.
45    ///
46    /// 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.
47    ///
48    /// Supported API versions: 1-5
49    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
50        self.throttle_time_ms = value;
51        self
52    }
53    /// Sets `error_code` to the passed value.
54    ///
55    /// The error code, or 0 if there was no error.
56    ///
57    /// Supported API versions: 0-5
58    pub fn with_error_code(mut self, value: i16) -> Self {
59        self.error_code = value;
60        self
61    }
62    /// Sets `groups` to the passed value.
63    ///
64    /// Each group in the response.
65    ///
66    /// Supported API versions: 0-5
67    pub fn with_groups(mut self, value: Vec<ListedGroup>) -> Self {
68        self.groups = value;
69        self
70    }
71    /// Sets unknown_tagged_fields to the passed value.
72    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73        self.unknown_tagged_fields = value;
74        self
75    }
76    /// Inserts an entry into unknown_tagged_fields.
77    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
78        self.unknown_tagged_fields.insert(key, value);
79        self
80    }
81}
82
83#[cfg(feature = "broker")]
84impl Encodable for ListGroupsResponse {
85    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86        if version < 0 || version > 5 {
87            bail!("specified version not supported by this message type");
88        }
89        if version >= 1 {
90            types::Int32.encode(buf, &self.throttle_time_ms)?;
91        }
92        types::Int16.encode(buf, &self.error_code)?;
93        if version >= 3 {
94            types::CompactArray(types::Struct { version }).encode(buf, &self.groups)?;
95        } else {
96            types::Array(types::Struct { version }).encode(buf, &self.groups)?;
97        }
98        if version >= 3 {
99            let num_tagged_fields = self.unknown_tagged_fields.len();
100            if num_tagged_fields > std::u32::MAX as usize {
101                bail!(
102                    "Too many tagged fields to encode ({} fields)",
103                    num_tagged_fields
104                );
105            }
106            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
107
108            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
109        }
110        Ok(())
111    }
112    fn compute_size(&self, version: i16) -> Result<usize> {
113        let mut total_size = 0;
114        if version >= 1 {
115            total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
116        }
117        total_size += types::Int16.compute_size(&self.error_code)?;
118        if version >= 3 {
119            total_size +=
120                types::CompactArray(types::Struct { version }).compute_size(&self.groups)?;
121        } else {
122            total_size += types::Array(types::Struct { version }).compute_size(&self.groups)?;
123        }
124        if version >= 3 {
125            let num_tagged_fields = self.unknown_tagged_fields.len();
126            if num_tagged_fields > std::u32::MAX as usize {
127                bail!(
128                    "Too many tagged fields to encode ({} fields)",
129                    num_tagged_fields
130                );
131            }
132            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
133
134            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
135        }
136        Ok(total_size)
137    }
138}
139
140#[cfg(feature = "client")]
141impl Decodable for ListGroupsResponse {
142    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
143        if version < 0 || version > 5 {
144            bail!("specified version not supported by this message type");
145        }
146        let throttle_time_ms = if version >= 1 {
147            types::Int32.decode(buf)?
148        } else {
149            0
150        };
151        let error_code = types::Int16.decode(buf)?;
152        let groups = if version >= 3 {
153            types::CompactArray(types::Struct { version }).decode(buf)?
154        } else {
155            types::Array(types::Struct { version }).decode(buf)?
156        };
157        let mut unknown_tagged_fields = BTreeMap::new();
158        if version >= 3 {
159            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
160            for _ in 0..num_tagged_fields {
161                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
162                let size: u32 = types::UnsignedVarInt.decode(buf)?;
163                let unknown_value = buf.try_get_bytes(size as usize)?;
164                unknown_tagged_fields.insert(tag as i32, unknown_value);
165            }
166        }
167        Ok(Self {
168            throttle_time_ms,
169            error_code,
170            groups,
171            unknown_tagged_fields,
172        })
173    }
174}
175
176impl Default for ListGroupsResponse {
177    fn default() -> Self {
178        Self {
179            throttle_time_ms: 0,
180            error_code: 0,
181            groups: Default::default(),
182            unknown_tagged_fields: BTreeMap::new(),
183        }
184    }
185}
186
187impl Message for ListGroupsResponse {
188    const VERSIONS: VersionRange = VersionRange { min: 0, max: 5 };
189    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
190}
191
192/// Valid versions: 0-5
193#[non_exhaustive]
194#[derive(Debug, Clone, PartialEq)]
195pub struct ListedGroup {
196    /// The group ID.
197    ///
198    /// Supported API versions: 0-5
199    pub group_id: super::GroupId,
200
201    /// The group protocol type.
202    ///
203    /// Supported API versions: 0-5
204    pub protocol_type: StrBytes,
205
206    /// The group state name.
207    ///
208    /// Supported API versions: 4-5
209    pub group_state: StrBytes,
210
211    /// The group type name.
212    ///
213    /// Supported API versions: 5
214    pub group_type: StrBytes,
215
216    /// Other tagged fields
217    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
218}
219
220impl ListedGroup {
221    /// Sets `group_id` to the passed value.
222    ///
223    /// The group ID.
224    ///
225    /// Supported API versions: 0-5
226    pub fn with_group_id(mut self, value: super::GroupId) -> Self {
227        self.group_id = value;
228        self
229    }
230    /// Sets `protocol_type` to the passed value.
231    ///
232    /// The group protocol type.
233    ///
234    /// Supported API versions: 0-5
235    pub fn with_protocol_type(mut self, value: StrBytes) -> Self {
236        self.protocol_type = value;
237        self
238    }
239    /// Sets `group_state` to the passed value.
240    ///
241    /// The group state name.
242    ///
243    /// Supported API versions: 4-5
244    pub fn with_group_state(mut self, value: StrBytes) -> Self {
245        self.group_state = value;
246        self
247    }
248    /// Sets `group_type` to the passed value.
249    ///
250    /// The group type name.
251    ///
252    /// Supported API versions: 5
253    pub fn with_group_type(mut self, value: StrBytes) -> Self {
254        self.group_type = value;
255        self
256    }
257    /// Sets unknown_tagged_fields to the passed value.
258    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
259        self.unknown_tagged_fields = value;
260        self
261    }
262    /// Inserts an entry into unknown_tagged_fields.
263    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
264        self.unknown_tagged_fields.insert(key, value);
265        self
266    }
267}
268
269#[cfg(feature = "broker")]
270impl Encodable for ListedGroup {
271    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
272        if version < 0 || version > 5 {
273            bail!("specified version not supported by this message type");
274        }
275        if version >= 3 {
276            types::CompactString.encode(buf, &self.group_id)?;
277        } else {
278            types::String.encode(buf, &self.group_id)?;
279        }
280        if version >= 3 {
281            types::CompactString.encode(buf, &self.protocol_type)?;
282        } else {
283            types::String.encode(buf, &self.protocol_type)?;
284        }
285        if version >= 4 {
286            types::CompactString.encode(buf, &self.group_state)?;
287        }
288        if version >= 5 {
289            types::CompactString.encode(buf, &self.group_type)?;
290        }
291        if version >= 3 {
292            let num_tagged_fields = self.unknown_tagged_fields.len();
293            if num_tagged_fields > std::u32::MAX as usize {
294                bail!(
295                    "Too many tagged fields to encode ({} fields)",
296                    num_tagged_fields
297                );
298            }
299            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
300
301            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
302        }
303        Ok(())
304    }
305    fn compute_size(&self, version: i16) -> Result<usize> {
306        let mut total_size = 0;
307        if version >= 3 {
308            total_size += types::CompactString.compute_size(&self.group_id)?;
309        } else {
310            total_size += types::String.compute_size(&self.group_id)?;
311        }
312        if version >= 3 {
313            total_size += types::CompactString.compute_size(&self.protocol_type)?;
314        } else {
315            total_size += types::String.compute_size(&self.protocol_type)?;
316        }
317        if version >= 4 {
318            total_size += types::CompactString.compute_size(&self.group_state)?;
319        }
320        if version >= 5 {
321            total_size += types::CompactString.compute_size(&self.group_type)?;
322        }
323        if version >= 3 {
324            let num_tagged_fields = self.unknown_tagged_fields.len();
325            if num_tagged_fields > std::u32::MAX as usize {
326                bail!(
327                    "Too many tagged fields to encode ({} fields)",
328                    num_tagged_fields
329                );
330            }
331            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
332
333            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
334        }
335        Ok(total_size)
336    }
337}
338
339#[cfg(feature = "client")]
340impl Decodable for ListedGroup {
341    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
342        if version < 0 || version > 5 {
343            bail!("specified version not supported by this message type");
344        }
345        let group_id = if version >= 3 {
346            types::CompactString.decode(buf)?
347        } else {
348            types::String.decode(buf)?
349        };
350        let protocol_type = if version >= 3 {
351            types::CompactString.decode(buf)?
352        } else {
353            types::String.decode(buf)?
354        };
355        let group_state = if version >= 4 {
356            types::CompactString.decode(buf)?
357        } else {
358            Default::default()
359        };
360        let group_type = if version >= 5 {
361            types::CompactString.decode(buf)?
362        } else {
363            Default::default()
364        };
365        let mut unknown_tagged_fields = BTreeMap::new();
366        if version >= 3 {
367            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
368            for _ in 0..num_tagged_fields {
369                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
370                let size: u32 = types::UnsignedVarInt.decode(buf)?;
371                let unknown_value = buf.try_get_bytes(size as usize)?;
372                unknown_tagged_fields.insert(tag as i32, unknown_value);
373            }
374        }
375        Ok(Self {
376            group_id,
377            protocol_type,
378            group_state,
379            group_type,
380            unknown_tagged_fields,
381        })
382    }
383}
384
385impl Default for ListedGroup {
386    fn default() -> Self {
387        Self {
388            group_id: Default::default(),
389            protocol_type: Default::default(),
390            group_state: Default::default(),
391            group_type: Default::default(),
392            unknown_tagged_fields: BTreeMap::new(),
393        }
394    }
395}
396
397impl Message for ListedGroup {
398    const VERSIONS: VersionRange = VersionRange { min: 0, max: 5 };
399    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
400}
401
402impl HeaderVersion for ListGroupsResponse {
403    fn header_version(version: i16) -> i16 {
404        if version >= 3 {
405            1
406        } else {
407            0
408        }
409    }
410}