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