Skip to main content

kacrab_protocol/generated/
initialize_share_group_state_request.rs

1//! Generated from InitializeShareGroupStateRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct InitializeShareGroupStateRequestData {
17    /// The group identifier.
18    pub group_id: KafkaString,
19    /// The data for the topics.
20    pub topics: Vec<InitializeStateData>,
21    pub _unknown_tagged_fields: Vec<RawTaggedField>,
22}
23impl Default for InitializeShareGroupStateRequestData {
24    fn default() -> Self {
25        Self {
26            group_id: KafkaString::default(),
27            topics: Vec::new(),
28            _unknown_tagged_fields: Vec::new(),
29        }
30    }
31}
32impl InitializeShareGroupStateRequestData {
33    pub fn with_group_id(mut self, value: KafkaString) -> Self {
34        self.group_id = value;
35        self
36    }
37    pub fn with_topics(mut self, value: Vec<InitializeStateData>) -> Self {
38        self.topics = value;
39        self
40    }
41    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
42        if version < 0 || version > 0 {
43            return Err(UnsupportedVersion::new(83, version).into());
44        }
45        let group_id;
46        let topics;
47        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
48        group_id = read_compact_string(buf)?;
49        topics = {
50            let len = read_compact_array_length(buf)?;
51            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
52            for _ in 0..len {
53                arr.push(InitializeStateData::read(buf, version)?);
54            }
55            arr
56        };
57        let tagged_fields = read_tagged_fields(buf)?;
58        for field in &tagged_fields {
59            match field.tag {
60                _ => {
61                    _unknown_tagged_fields.push(field.clone());
62                },
63            }
64        }
65        Ok(Self {
66            group_id,
67            topics,
68            _unknown_tagged_fields,
69        })
70    }
71    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
72        if version < 0 || version > 0 {
73            return Err(UnsupportedVersion::new(83, version).into());
74        }
75        write_compact_string(buf, &self.group_id)?;
76        write_compact_array_length(buf, self.topics.len() as i32);
77        for el in &self.topics {
78            el.write(buf, version)?;
79        }
80        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
81        all_tags.sort_by_key(|f| f.tag);
82        write_tagged_fields(buf, &all_tags)?;
83        Ok(())
84    }
85    pub fn encoded_len(&self, version: i16) -> Result<usize> {
86        if version < 0 || version > 0 {
87            return Err(UnsupportedVersion::new(83, version).into());
88        }
89        let mut len: usize = 0;
90        len += compact_string_len(&self.group_id)?;
91        len += compact_array_length_len(self.topics.len() as i32);
92        for el in &self.topics {
93            len += el.encoded_len(version)?;
94        }
95        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
96        all_tags.sort_by_key(|f| f.tag);
97        len += tagged_fields_len(&all_tags)?;
98        Ok(len)
99    }
100}
101#[derive(Debug, Clone, PartialEq)]
102pub struct InitializeStateData {
103    /// The topic identifier.
104    pub topic_id: KafkaUuid,
105    /// The data for the partitions.
106    pub partitions: Vec<PartitionData>,
107    pub _unknown_tagged_fields: Vec<RawTaggedField>,
108}
109impl Default for InitializeStateData {
110    fn default() -> Self {
111        Self {
112            topic_id: KafkaUuid::ZERO,
113            partitions: Vec::new(),
114            _unknown_tagged_fields: Vec::new(),
115        }
116    }
117}
118impl InitializeStateData {
119    pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
120        self.topic_id = value;
121        self
122    }
123    pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
124        self.partitions = value;
125        self
126    }
127    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
128        let topic_id;
129        let partitions;
130        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
131        topic_id = read_uuid(buf)?;
132        partitions = {
133            let len = read_compact_array_length(buf)?;
134            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
135            for _ in 0..len {
136                arr.push(PartitionData::read(buf, version)?);
137            }
138            arr
139        };
140        let tagged_fields = read_tagged_fields(buf)?;
141        for field in &tagged_fields {
142            match field.tag {
143                _ => {
144                    _unknown_tagged_fields.push(field.clone());
145                },
146            }
147        }
148        Ok(Self {
149            topic_id,
150            partitions,
151            _unknown_tagged_fields,
152        })
153    }
154    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
155        write_uuid(buf, &self.topic_id);
156        write_compact_array_length(buf, self.partitions.len() as i32);
157        for el in &self.partitions {
158            el.write(buf, version)?;
159        }
160        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
161        all_tags.sort_by_key(|f| f.tag);
162        write_tagged_fields(buf, &all_tags)?;
163        Ok(())
164    }
165    pub fn encoded_len(&self, version: i16) -> Result<usize> {
166        let mut len: usize = 0;
167        len += 16;
168        len += compact_array_length_len(self.partitions.len() as i32);
169        for el in &self.partitions {
170            len += el.encoded_len(version)?;
171        }
172        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
173        all_tags.sort_by_key(|f| f.tag);
174        len += tagged_fields_len(&all_tags)?;
175        Ok(len)
176    }
177}
178#[derive(Debug, Clone, PartialEq)]
179pub struct PartitionData {
180    /// The partition index.
181    pub partition: i32,
182    /// The state epoch for this share-partition.
183    pub state_epoch: i32,
184    /// The share-partition start offset, or -1 if the start offset is not being initialized.
185    pub start_offset: i64,
186    pub _unknown_tagged_fields: Vec<RawTaggedField>,
187}
188impl Default for PartitionData {
189    fn default() -> Self {
190        Self {
191            partition: 0_i32,
192            state_epoch: 0_i32,
193            start_offset: 0_i64,
194            _unknown_tagged_fields: Vec::new(),
195        }
196    }
197}
198impl PartitionData {
199    pub fn with_partition(mut self, value: i32) -> Self {
200        self.partition = value;
201        self
202    }
203    pub fn with_state_epoch(mut self, value: i32) -> Self {
204        self.state_epoch = value;
205        self
206    }
207    pub fn with_start_offset(mut self, value: i64) -> Self {
208        self.start_offset = value;
209        self
210    }
211    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
212        let partition;
213        let state_epoch;
214        let start_offset;
215        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
216        partition = read_i32(buf)?;
217        state_epoch = read_i32(buf)?;
218        start_offset = read_i64(buf)?;
219        let tagged_fields = read_tagged_fields(buf)?;
220        for field in &tagged_fields {
221            match field.tag {
222                _ => {
223                    _unknown_tagged_fields.push(field.clone());
224                },
225            }
226        }
227        Ok(Self {
228            partition,
229            state_epoch,
230            start_offset,
231            _unknown_tagged_fields,
232        })
233    }
234    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
235        write_i32(buf, self.partition);
236        write_i32(buf, self.state_epoch);
237        write_i64(buf, self.start_offset);
238        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
239        all_tags.sort_by_key(|f| f.tag);
240        write_tagged_fields(buf, &all_tags)?;
241        Ok(())
242    }
243    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
244        let mut len: usize = 0;
245        len += 4;
246        len += 4;
247        len += 8;
248        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
249        all_tags.sort_by_key(|f| f.tag);
250        len += tagged_fields_len(&all_tags)?;
251        Ok(len)
252    }
253}