kafka_protocol/messages/
alter_share_group_offsets_response.rs

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