Skip to main content

kacrab_protocol/generated/
share_acknowledge_request.rs

1//! Generated from ShareAcknowledgeRequest.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 ShareAcknowledgeRequestData {
17    /// The group identifier.
18    pub group_id: Option<KafkaString>,
19    /// The member ID.
20    pub member_id: Option<KafkaString>,
21    /// The current share session epoch: 0 to open a share session; -1 to close it; otherwise
22    /// increments for consecutive requests.
23    pub share_session_epoch: i32,
24    /// Whether Renew type acknowledgements present in AcknowledgementBatches.
25    pub is_renew_ack: bool,
26    /// The topics containing records to acknowledge.
27    pub topics: Vec<AcknowledgeTopic>,
28    pub _unknown_tagged_fields: Vec<RawTaggedField>,
29}
30impl Default for ShareAcknowledgeRequestData {
31    fn default() -> Self {
32        Self {
33            group_id: None,
34            member_id: None,
35            share_session_epoch: 0_i32,
36            is_renew_ack: false,
37            topics: Vec::new(),
38            _unknown_tagged_fields: Vec::new(),
39        }
40    }
41}
42impl ShareAcknowledgeRequestData {
43    pub fn with_group_id(mut self, value: Option<KafkaString>) -> Self {
44        self.group_id = value;
45        self
46    }
47    pub fn with_member_id(mut self, value: Option<KafkaString>) -> Self {
48        self.member_id = value;
49        self
50    }
51    pub fn with_share_session_epoch(mut self, value: i32) -> Self {
52        self.share_session_epoch = value;
53        self
54    }
55    pub fn with_is_renew_ack(mut self, value: bool) -> Self {
56        self.is_renew_ack = value;
57        self
58    }
59    pub fn with_topics(mut self, value: Vec<AcknowledgeTopic>) -> Self {
60        self.topics = value;
61        self
62    }
63    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
64        if version < 1 || version > 2 {
65            return Err(UnsupportedVersion::new(79, version).into());
66        }
67        let group_id;
68        let member_id;
69        let share_session_epoch;
70        let mut is_renew_ack = false;
71        let topics;
72        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
73        group_id = read_compact_nullable_string(buf)?;
74        member_id = read_compact_nullable_string(buf)?;
75        share_session_epoch = read_i32(buf)?;
76        if version >= 2 {
77            is_renew_ack = read_bool(buf)?;
78        }
79        topics = {
80            let len = read_compact_array_length(buf)?;
81            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
82            for _ in 0..len {
83                arr.push(AcknowledgeTopic::read(buf, version)?);
84            }
85            arr
86        };
87        let tagged_fields = read_tagged_fields(buf)?;
88        for field in &tagged_fields {
89            match field.tag {
90                _ => {
91                    _unknown_tagged_fields.push(field.clone());
92                },
93            }
94        }
95        Ok(Self {
96            group_id,
97            member_id,
98            share_session_epoch,
99            is_renew_ack,
100            topics,
101            _unknown_tagged_fields,
102        })
103    }
104    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
105        if version < 1 || version > 2 {
106            return Err(UnsupportedVersion::new(79, version).into());
107        }
108        write_compact_nullable_string(buf, self.group_id.as_ref())?;
109        write_compact_nullable_string(buf, self.member_id.as_ref())?;
110        write_i32(buf, self.share_session_epoch);
111        if version >= 2 {
112            write_bool(buf, self.is_renew_ack);
113        } else if self.is_renew_ack != false {
114            return Err(UnsupportedFieldVersion::new(79, "is_renew_ack", version).into());
115        }
116        write_compact_array_length(buf, self.topics.len() as i32);
117        for el in &self.topics {
118            el.write(buf, version)?;
119        }
120        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
121        all_tags.sort_by_key(|f| f.tag);
122        write_tagged_fields(buf, &all_tags)?;
123        Ok(())
124    }
125    pub fn encoded_len(&self, version: i16) -> Result<usize> {
126        if version < 1 || version > 2 {
127            return Err(UnsupportedVersion::new(79, version).into());
128        }
129        let mut len: usize = 0;
130        len += compact_nullable_string_len(self.group_id.as_ref())?;
131        len += compact_nullable_string_len(self.member_id.as_ref())?;
132        len += 4;
133        if version >= 2 {
134            len += 1;
135        } else if self.is_renew_ack != false {
136            return Err(UnsupportedFieldVersion::new(79, "is_renew_ack", version).into());
137        }
138        len += compact_array_length_len(self.topics.len() as i32);
139        for el in &self.topics {
140            len += el.encoded_len(version)?;
141        }
142        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
143        all_tags.sort_by_key(|f| f.tag);
144        len += tagged_fields_len(&all_tags)?;
145        Ok(len)
146    }
147}
148#[derive(Debug, Clone, PartialEq)]
149pub struct AcknowledgeTopic {
150    /// The unique topic ID.
151    pub topic_id: KafkaUuid,
152    /// The partitions containing records to acknowledge.
153    pub partitions: Vec<AcknowledgePartition>,
154    pub _unknown_tagged_fields: Vec<RawTaggedField>,
155}
156impl Default for AcknowledgeTopic {
157    fn default() -> Self {
158        Self {
159            topic_id: KafkaUuid::ZERO,
160            partitions: Vec::new(),
161            _unknown_tagged_fields: Vec::new(),
162        }
163    }
164}
165impl AcknowledgeTopic {
166    pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
167        self.topic_id = value;
168        self
169    }
170    pub fn with_partitions(mut self, value: Vec<AcknowledgePartition>) -> Self {
171        self.partitions = value;
172        self
173    }
174    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
175        let topic_id;
176        let partitions;
177        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
178        topic_id = read_uuid(buf)?;
179        partitions = {
180            let len = read_compact_array_length(buf)?;
181            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
182            for _ in 0..len {
183                arr.push(AcknowledgePartition::read(buf, version)?);
184            }
185            arr
186        };
187        let tagged_fields = read_tagged_fields(buf)?;
188        for field in &tagged_fields {
189            match field.tag {
190                _ => {
191                    _unknown_tagged_fields.push(field.clone());
192                },
193            }
194        }
195        Ok(Self {
196            topic_id,
197            partitions,
198            _unknown_tagged_fields,
199        })
200    }
201    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
202        write_uuid(buf, &self.topic_id);
203        write_compact_array_length(buf, self.partitions.len() as i32);
204        for el in &self.partitions {
205            el.write(buf, version)?;
206        }
207        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
208        all_tags.sort_by_key(|f| f.tag);
209        write_tagged_fields(buf, &all_tags)?;
210        Ok(())
211    }
212    pub fn encoded_len(&self, version: i16) -> Result<usize> {
213        let mut len: usize = 0;
214        len += 16;
215        len += compact_array_length_len(self.partitions.len() as i32);
216        for el in &self.partitions {
217            len += el.encoded_len(version)?;
218        }
219        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
220        all_tags.sort_by_key(|f| f.tag);
221        len += tagged_fields_len(&all_tags)?;
222        Ok(len)
223    }
224}
225#[derive(Debug, Clone, PartialEq)]
226pub struct AcknowledgePartition {
227    /// The partition index.
228    pub partition_index: i32,
229    /// Record batches to acknowledge.
230    pub acknowledgement_batches: Vec<AcknowledgementBatch>,
231    pub _unknown_tagged_fields: Vec<RawTaggedField>,
232}
233impl Default for AcknowledgePartition {
234    fn default() -> Self {
235        Self {
236            partition_index: 0_i32,
237            acknowledgement_batches: Vec::new(),
238            _unknown_tagged_fields: Vec::new(),
239        }
240    }
241}
242impl AcknowledgePartition {
243    pub fn with_partition_index(mut self, value: i32) -> Self {
244        self.partition_index = value;
245        self
246    }
247    pub fn with_acknowledgement_batches(mut self, value: Vec<AcknowledgementBatch>) -> Self {
248        self.acknowledgement_batches = value;
249        self
250    }
251    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
252        let partition_index;
253        let acknowledgement_batches;
254        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
255        partition_index = read_i32(buf)?;
256        acknowledgement_batches = {
257            let len = read_compact_array_length(buf)?;
258            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
259            for _ in 0..len {
260                arr.push(AcknowledgementBatch::read(buf, version)?);
261            }
262            arr
263        };
264        let tagged_fields = read_tagged_fields(buf)?;
265        for field in &tagged_fields {
266            match field.tag {
267                _ => {
268                    _unknown_tagged_fields.push(field.clone());
269                },
270            }
271        }
272        Ok(Self {
273            partition_index,
274            acknowledgement_batches,
275            _unknown_tagged_fields,
276        })
277    }
278    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
279        write_i32(buf, self.partition_index);
280        write_compact_array_length(buf, self.acknowledgement_batches.len() as i32);
281        for el in &self.acknowledgement_batches {
282            el.write(buf, version)?;
283        }
284        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
285        all_tags.sort_by_key(|f| f.tag);
286        write_tagged_fields(buf, &all_tags)?;
287        Ok(())
288    }
289    pub fn encoded_len(&self, version: i16) -> Result<usize> {
290        let mut len: usize = 0;
291        len += 4;
292        len += compact_array_length_len(self.acknowledgement_batches.len() as i32);
293        for el in &self.acknowledgement_batches {
294            len += el.encoded_len(version)?;
295        }
296        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
297        all_tags.sort_by_key(|f| f.tag);
298        len += tagged_fields_len(&all_tags)?;
299        Ok(len)
300    }
301}
302#[derive(Debug, Clone, PartialEq)]
303pub struct AcknowledgementBatch {
304    /// First offset of batch of records to acknowledge.
305    pub first_offset: i64,
306    /// Last offset (inclusive) of batch of records to acknowledge.
307    pub last_offset: i64,
308    /// Array of acknowledge types - 0:Gap,1:Accept,2:Release,3:Reject,4:Renew.
309    pub acknowledge_types: Vec<i8>,
310    pub _unknown_tagged_fields: Vec<RawTaggedField>,
311}
312impl Default for AcknowledgementBatch {
313    fn default() -> Self {
314        Self {
315            first_offset: 0_i64,
316            last_offset: 0_i64,
317            acknowledge_types: Vec::new(),
318            _unknown_tagged_fields: Vec::new(),
319        }
320    }
321}
322impl AcknowledgementBatch {
323    pub fn with_first_offset(mut self, value: i64) -> Self {
324        self.first_offset = value;
325        self
326    }
327    pub fn with_last_offset(mut self, value: i64) -> Self {
328        self.last_offset = value;
329        self
330    }
331    pub fn with_acknowledge_types(mut self, value: Vec<i8>) -> Self {
332        self.acknowledge_types = value;
333        self
334    }
335    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
336        let first_offset;
337        let last_offset;
338        let acknowledge_types;
339        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
340        first_offset = read_i64(buf)?;
341        last_offset = read_i64(buf)?;
342        acknowledge_types = {
343            let len = read_compact_array_length(buf)?;
344            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
345            for _ in 0..len {
346                arr.push(read_i8(buf)?);
347            }
348            arr
349        };
350        let tagged_fields = read_tagged_fields(buf)?;
351        for field in &tagged_fields {
352            match field.tag {
353                _ => {
354                    _unknown_tagged_fields.push(field.clone());
355                },
356            }
357        }
358        Ok(Self {
359            first_offset,
360            last_offset,
361            acknowledge_types,
362            _unknown_tagged_fields,
363        })
364    }
365    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
366        write_i64(buf, self.first_offset);
367        write_i64(buf, self.last_offset);
368        write_compact_array_length(buf, self.acknowledge_types.len() as i32);
369        for el in &self.acknowledge_types {
370            write_i8(buf, *el);
371        }
372        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
373        all_tags.sort_by_key(|f| f.tag);
374        write_tagged_fields(buf, &all_tags)?;
375        Ok(())
376    }
377    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
378        let mut len: usize = 0;
379        len += 8;
380        len += 8;
381        len += compact_array_length_len(self.acknowledge_types.len() as i32);
382        len += self.acknowledge_types.len() * 1usize;
383        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
384        all_tags.sort_by_key(|f| f.tag);
385        len += tagged_fields_len(&all_tags)?;
386        Ok(len)
387    }
388}