kafka_protocol/messages/
initialize_share_group_state_request.rs

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