kafka_protocol/messages/
delete_share_group_state_response.rs

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