kafka_protocol/messages/
delete_groups_response.rs

1//! DeleteGroupsResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/DeleteGroupsResponse.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-2
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct DeletableGroupResult {
24    /// The group id
25    ///
26    /// Supported API versions: 0-2
27    pub group_id: super::GroupId,
28
29    /// The deletion error, or 0 if the deletion succeeded.
30    ///
31    /// Supported API versions: 0-2
32    pub error_code: i16,
33
34    /// Other tagged fields
35    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl DeletableGroupResult {
39    /// Sets `group_id` to the passed value.
40    ///
41    /// The group id
42    ///
43    /// Supported API versions: 0-2
44    pub fn with_group_id(mut self, value: super::GroupId) -> Self {
45        self.group_id = value;
46        self
47    }
48    /// Sets `error_code` to the passed value.
49    ///
50    /// The deletion error, or 0 if the deletion succeeded.
51    ///
52    /// Supported API versions: 0-2
53    pub fn with_error_code(mut self, value: i16) -> Self {
54        self.error_code = value;
55        self
56    }
57    /// Sets unknown_tagged_fields to the passed value.
58    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
59        self.unknown_tagged_fields = value;
60        self
61    }
62    /// Inserts an entry into unknown_tagged_fields.
63    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
64        self.unknown_tagged_fields.insert(key, value);
65        self
66    }
67}
68
69#[cfg(feature = "broker")]
70impl Encodable for DeletableGroupResult {
71    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
72        if version >= 2 {
73            types::CompactString.encode(buf, &self.group_id)?;
74        } else {
75            types::String.encode(buf, &self.group_id)?;
76        }
77        types::Int16.encode(buf, &self.error_code)?;
78        if version >= 2 {
79            let num_tagged_fields = self.unknown_tagged_fields.len();
80            if num_tagged_fields > std::u32::MAX as usize {
81                bail!(
82                    "Too many tagged fields to encode ({} fields)",
83                    num_tagged_fields
84                );
85            }
86            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
87
88            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
89        }
90        Ok(())
91    }
92    fn compute_size(&self, version: i16) -> Result<usize> {
93        let mut total_size = 0;
94        if version >= 2 {
95            total_size += types::CompactString.compute_size(&self.group_id)?;
96        } else {
97            total_size += types::String.compute_size(&self.group_id)?;
98        }
99        total_size += types::Int16.compute_size(&self.error_code)?;
100        if version >= 2 {
101            let num_tagged_fields = self.unknown_tagged_fields.len();
102            if num_tagged_fields > std::u32::MAX as usize {
103                bail!(
104                    "Too many tagged fields to encode ({} fields)",
105                    num_tagged_fields
106                );
107            }
108            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
109
110            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
111        }
112        Ok(total_size)
113    }
114}
115
116#[cfg(feature = "client")]
117impl Decodable for DeletableGroupResult {
118    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
119        let group_id = if version >= 2 {
120            types::CompactString.decode(buf)?
121        } else {
122            types::String.decode(buf)?
123        };
124        let error_code = types::Int16.decode(buf)?;
125        let mut unknown_tagged_fields = BTreeMap::new();
126        if version >= 2 {
127            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
128            for _ in 0..num_tagged_fields {
129                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
130                let size: u32 = types::UnsignedVarInt.decode(buf)?;
131                let unknown_value = buf.try_get_bytes(size as usize)?;
132                unknown_tagged_fields.insert(tag as i32, unknown_value);
133            }
134        }
135        Ok(Self {
136            group_id,
137            error_code,
138            unknown_tagged_fields,
139        })
140    }
141}
142
143impl Default for DeletableGroupResult {
144    fn default() -> Self {
145        Self {
146            group_id: Default::default(),
147            error_code: 0,
148            unknown_tagged_fields: BTreeMap::new(),
149        }
150    }
151}
152
153impl Message for DeletableGroupResult {
154    const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
155    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
156}
157
158/// Valid versions: 0-2
159#[non_exhaustive]
160#[derive(Debug, Clone, PartialEq)]
161pub struct DeleteGroupsResponse {
162    /// 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.
163    ///
164    /// Supported API versions: 0-2
165    pub throttle_time_ms: i32,
166
167    /// The deletion results
168    ///
169    /// Supported API versions: 0-2
170    pub results: Vec<DeletableGroupResult>,
171
172    /// Other tagged fields
173    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
174}
175
176impl DeleteGroupsResponse {
177    /// Sets `throttle_time_ms` to the passed value.
178    ///
179    /// 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.
180    ///
181    /// Supported API versions: 0-2
182    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
183        self.throttle_time_ms = value;
184        self
185    }
186    /// Sets `results` to the passed value.
187    ///
188    /// The deletion results
189    ///
190    /// Supported API versions: 0-2
191    pub fn with_results(mut self, value: Vec<DeletableGroupResult>) -> Self {
192        self.results = value;
193        self
194    }
195    /// Sets unknown_tagged_fields to the passed value.
196    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
197        self.unknown_tagged_fields = value;
198        self
199    }
200    /// Inserts an entry into unknown_tagged_fields.
201    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
202        self.unknown_tagged_fields.insert(key, value);
203        self
204    }
205}
206
207#[cfg(feature = "broker")]
208impl Encodable for DeleteGroupsResponse {
209    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
210        types::Int32.encode(buf, &self.throttle_time_ms)?;
211        if version >= 2 {
212            types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
213        } else {
214            types::Array(types::Struct { version }).encode(buf, &self.results)?;
215        }
216        if version >= 2 {
217            let num_tagged_fields = self.unknown_tagged_fields.len();
218            if num_tagged_fields > std::u32::MAX as usize {
219                bail!(
220                    "Too many tagged fields to encode ({} fields)",
221                    num_tagged_fields
222                );
223            }
224            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
225
226            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
227        }
228        Ok(())
229    }
230    fn compute_size(&self, version: i16) -> Result<usize> {
231        let mut total_size = 0;
232        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
233        if version >= 2 {
234            total_size +=
235                types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
236        } else {
237            total_size += types::Array(types::Struct { version }).compute_size(&self.results)?;
238        }
239        if version >= 2 {
240            let num_tagged_fields = self.unknown_tagged_fields.len();
241            if num_tagged_fields > std::u32::MAX as usize {
242                bail!(
243                    "Too many tagged fields to encode ({} fields)",
244                    num_tagged_fields
245                );
246            }
247            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
248
249            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
250        }
251        Ok(total_size)
252    }
253}
254
255#[cfg(feature = "client")]
256impl Decodable for DeleteGroupsResponse {
257    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
258        let throttle_time_ms = types::Int32.decode(buf)?;
259        let results = if version >= 2 {
260            types::CompactArray(types::Struct { version }).decode(buf)?
261        } else {
262            types::Array(types::Struct { version }).decode(buf)?
263        };
264        let mut unknown_tagged_fields = BTreeMap::new();
265        if version >= 2 {
266            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
267            for _ in 0..num_tagged_fields {
268                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
269                let size: u32 = types::UnsignedVarInt.decode(buf)?;
270                let unknown_value = buf.try_get_bytes(size as usize)?;
271                unknown_tagged_fields.insert(tag as i32, unknown_value);
272            }
273        }
274        Ok(Self {
275            throttle_time_ms,
276            results,
277            unknown_tagged_fields,
278        })
279    }
280}
281
282impl Default for DeleteGroupsResponse {
283    fn default() -> Self {
284        Self {
285            throttle_time_ms: 0,
286            results: Default::default(),
287            unknown_tagged_fields: BTreeMap::new(),
288        }
289    }
290}
291
292impl Message for DeleteGroupsResponse {
293    const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
294    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
295}
296
297impl HeaderVersion for DeleteGroupsResponse {
298    fn header_version(version: i16) -> i16 {
299        if version >= 2 {
300            1
301        } else {
302            0
303        }
304    }
305}