kafka_protocol/messages/
read_share_group_state_summary_response.rs

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