Skip to main content

kacrab_protocol/generated/
offset_commit_request.rs

1//! Generated from OffsetCommitRequest.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 OffsetCommitRequestData {
17    /// The unique group identifier.
18    pub group_id: KafkaString,
19    /// The generation of the group if using the classic group protocol or the member epoch if
20    /// using the consumer protocol.
21    pub generation_id_or_member_epoch: i32,
22    /// The member ID assigned by the group coordinator.
23    pub member_id: KafkaString,
24    /// The unique identifier of the consumer instance provided by end user.
25    pub group_instance_id: Option<KafkaString>,
26    /// The time period in ms to retain the offset.
27    pub retention_time_ms: i64,
28    /// The topics to commit offsets for.
29    pub topics: Vec<OffsetCommitRequestTopic>,
30    pub _unknown_tagged_fields: Vec<RawTaggedField>,
31}
32impl Default for OffsetCommitRequestData {
33    fn default() -> Self {
34        Self {
35            group_id: KafkaString::default(),
36            generation_id_or_member_epoch: -1i32,
37            member_id: KafkaString::default(),
38            group_instance_id: None,
39            retention_time_ms: -1i64,
40            topics: Vec::new(),
41            _unknown_tagged_fields: Vec::new(),
42        }
43    }
44}
45impl OffsetCommitRequestData {
46    pub fn with_group_id(mut self, value: KafkaString) -> Self {
47        self.group_id = value;
48        self
49    }
50    pub fn with_generation_id_or_member_epoch(mut self, value: i32) -> Self {
51        self.generation_id_or_member_epoch = value;
52        self
53    }
54    pub fn with_member_id(mut self, value: KafkaString) -> Self {
55        self.member_id = value;
56        self
57    }
58    pub fn with_group_instance_id(mut self, value: Option<KafkaString>) -> Self {
59        self.group_instance_id = value;
60        self
61    }
62    pub fn with_retention_time_ms(mut self, value: i64) -> Self {
63        self.retention_time_ms = value;
64        self
65    }
66    pub fn with_topics(mut self, value: Vec<OffsetCommitRequestTopic>) -> Self {
67        self.topics = value;
68        self
69    }
70    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
71        if version < 2 || version > 10 {
72            return Err(UnsupportedVersion::new(8, version).into());
73        }
74        let group_id;
75        let generation_id_or_member_epoch;
76        let member_id;
77        let mut group_instance_id = None;
78        let mut retention_time_ms = -1i64;
79        let topics;
80        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
81        if version >= 8 {
82            group_id = read_compact_string(buf)?;
83        } else {
84            group_id = read_string(buf)?;
85        }
86        generation_id_or_member_epoch = read_i32(buf)?;
87        if version >= 8 {
88            member_id = read_compact_string(buf)?;
89        } else {
90            member_id = read_string(buf)?;
91        }
92        if version >= 7 {
93            if version >= 8 {
94                group_instance_id = read_compact_nullable_string(buf)?;
95            } else {
96                group_instance_id = read_nullable_string(buf)?;
97            }
98        }
99        if version <= 4 {
100            retention_time_ms = read_i64(buf)?;
101        }
102        if version >= 8 {
103            topics = {
104                let len = read_compact_array_length(buf)?;
105                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
106                for _ in 0..len {
107                    arr.push(OffsetCommitRequestTopic::read(buf, version)?);
108                }
109                arr
110            };
111        } else {
112            topics = {
113                let len = read_array_length(buf)?;
114                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
115                for _ in 0..len {
116                    arr.push(OffsetCommitRequestTopic::read(buf, version)?);
117                }
118                arr
119            };
120        }
121        if version >= 8 {
122            let tagged_fields = read_tagged_fields(buf)?;
123            for field in &tagged_fields {
124                match field.tag {
125                    _ => {
126                        _unknown_tagged_fields.push(field.clone());
127                    },
128                }
129            }
130        }
131        Ok(Self {
132            group_id,
133            generation_id_or_member_epoch,
134            member_id,
135            group_instance_id,
136            retention_time_ms,
137            topics,
138            _unknown_tagged_fields,
139        })
140    }
141    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
142        if version < 2 || version > 10 {
143            return Err(UnsupportedVersion::new(8, version).into());
144        }
145        if version >= 8 {
146            write_compact_string(buf, &self.group_id)?;
147        } else {
148            write_string(buf, &self.group_id)?;
149        }
150        write_i32(buf, self.generation_id_or_member_epoch);
151        if version >= 8 {
152            write_compact_string(buf, &self.member_id)?;
153        } else {
154            write_string(buf, &self.member_id)?;
155        }
156        if version >= 7 {
157            if version >= 8 {
158                write_compact_nullable_string(buf, self.group_instance_id.as_ref())?;
159            } else {
160                write_nullable_string(buf, self.group_instance_id.as_ref())?;
161            }
162        } else if self.group_instance_id != None {
163            return Err(UnsupportedFieldVersion::new(8, "group_instance_id", version).into());
164        }
165        if version <= 4 {
166            write_i64(buf, self.retention_time_ms);
167        } else if self.retention_time_ms != -1i64 {
168            return Err(UnsupportedFieldVersion::new(8, "retention_time_ms", version).into());
169        }
170        if version >= 8 {
171            write_compact_array_length(buf, self.topics.len() as i32);
172            for el in &self.topics {
173                el.write(buf, version)?;
174            }
175        } else {
176            write_array_length(buf, self.topics.len() as i32);
177            for el in &self.topics {
178                el.write(buf, version)?;
179            }
180        }
181        if version >= 8 {
182            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
183            all_tags.sort_by_key(|f| f.tag);
184            write_tagged_fields(buf, &all_tags)?;
185        }
186        Ok(())
187    }
188    pub fn encoded_len(&self, version: i16) -> Result<usize> {
189        if version < 2 || version > 10 {
190            return Err(UnsupportedVersion::new(8, version).into());
191        }
192        let mut len: usize = 0;
193        if version >= 8 {
194            len += compact_string_len(&self.group_id)?;
195        } else {
196            len += string_len(&self.group_id)?;
197        }
198        len += 4;
199        if version >= 8 {
200            len += compact_string_len(&self.member_id)?;
201        } else {
202            len += string_len(&self.member_id)?;
203        }
204        if version >= 7 {
205            if version >= 8 {
206                len += compact_nullable_string_len(self.group_instance_id.as_ref())?;
207            } else {
208                len += nullable_string_len(self.group_instance_id.as_ref())?;
209            }
210        } else if self.group_instance_id != None {
211            return Err(UnsupportedFieldVersion::new(8, "group_instance_id", version).into());
212        }
213        if version <= 4 {
214            len += 8;
215        } else if self.retention_time_ms != -1i64 {
216            return Err(UnsupportedFieldVersion::new(8, "retention_time_ms", version).into());
217        }
218        if version >= 8 {
219            len += compact_array_length_len(self.topics.len() as i32);
220            for el in &self.topics {
221                len += el.encoded_len(version)?;
222            }
223        } else {
224            len += array_length_len();
225            for el in &self.topics {
226                len += el.encoded_len(version)?;
227            }
228        }
229        if version >= 8 {
230            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
231            all_tags.sort_by_key(|f| f.tag);
232            len += tagged_fields_len(&all_tags)?;
233        }
234        Ok(len)
235    }
236}
237#[derive(Debug, Clone, PartialEq)]
238pub struct OffsetCommitRequestTopic {
239    /// The topic name.
240    pub name: KafkaString,
241    /// The topic ID.
242    pub topic_id: KafkaUuid,
243    /// Each partition to commit offsets for.
244    pub partitions: Vec<OffsetCommitRequestPartition>,
245    pub _unknown_tagged_fields: Vec<RawTaggedField>,
246}
247impl Default for OffsetCommitRequestTopic {
248    fn default() -> Self {
249        Self {
250            name: KafkaString::default(),
251            topic_id: KafkaUuid::ZERO,
252            partitions: Vec::new(),
253            _unknown_tagged_fields: Vec::new(),
254        }
255    }
256}
257impl OffsetCommitRequestTopic {
258    pub fn with_name(mut self, value: KafkaString) -> Self {
259        self.name = value;
260        self
261    }
262    pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
263        self.topic_id = value;
264        self
265    }
266    pub fn with_partitions(mut self, value: Vec<OffsetCommitRequestPartition>) -> Self {
267        self.partitions = value;
268        self
269    }
270    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
271        let mut name = KafkaString::default();
272        let mut topic_id = KafkaUuid::ZERO;
273        let partitions;
274        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
275        if version <= 9 {
276            if version >= 8 {
277                name = read_compact_string(buf)?;
278            } else {
279                name = read_string(buf)?;
280            }
281        }
282        if version >= 10 {
283            topic_id = read_uuid(buf)?;
284        }
285        if version >= 8 {
286            partitions = {
287                let len = read_compact_array_length(buf)?;
288                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
289                for _ in 0..len {
290                    arr.push(OffsetCommitRequestPartition::read(buf, version)?);
291                }
292                arr
293            };
294        } else {
295            partitions = {
296                let len = read_array_length(buf)?;
297                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
298                for _ in 0..len {
299                    arr.push(OffsetCommitRequestPartition::read(buf, version)?);
300                }
301                arr
302            };
303        }
304        if version >= 8 {
305            let tagged_fields = read_tagged_fields(buf)?;
306            for field in &tagged_fields {
307                match field.tag {
308                    _ => {
309                        _unknown_tagged_fields.push(field.clone());
310                    },
311                }
312            }
313        }
314        Ok(Self {
315            name,
316            topic_id,
317            partitions,
318            _unknown_tagged_fields,
319        })
320    }
321    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
322        if version <= 9 {
323            if version >= 8 {
324                write_compact_string(buf, &self.name)?;
325            } else {
326                write_string(buf, &self.name)?;
327            }
328        } else if self.name != KafkaString::default() {
329            return Err(UnsupportedFieldVersion::new(8, "name", version).into());
330        }
331        if version >= 10 {
332            write_uuid(buf, &self.topic_id);
333        } else if self.topic_id != KafkaUuid::ZERO {
334            return Err(UnsupportedFieldVersion::new(8, "topic_id", version).into());
335        }
336        if version >= 8 {
337            write_compact_array_length(buf, self.partitions.len() as i32);
338            for el in &self.partitions {
339                el.write(buf, version)?;
340            }
341        } else {
342            write_array_length(buf, self.partitions.len() as i32);
343            for el in &self.partitions {
344                el.write(buf, version)?;
345            }
346        }
347        if version >= 8 {
348            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
349            all_tags.sort_by_key(|f| f.tag);
350            write_tagged_fields(buf, &all_tags)?;
351        }
352        Ok(())
353    }
354    pub fn encoded_len(&self, version: i16) -> Result<usize> {
355        let mut len: usize = 0;
356        if version <= 9 {
357            if version >= 8 {
358                len += compact_string_len(&self.name)?;
359            } else {
360                len += string_len(&self.name)?;
361            }
362        } else if self.name != KafkaString::default() {
363            return Err(UnsupportedFieldVersion::new(8, "name", version).into());
364        }
365        if version >= 10 {
366            len += 16;
367        } else if self.topic_id != KafkaUuid::ZERO {
368            return Err(UnsupportedFieldVersion::new(8, "topic_id", version).into());
369        }
370        if version >= 8 {
371            len += compact_array_length_len(self.partitions.len() as i32);
372            for el in &self.partitions {
373                len += el.encoded_len(version)?;
374            }
375        } else {
376            len += array_length_len();
377            for el in &self.partitions {
378                len += el.encoded_len(version)?;
379            }
380        }
381        if version >= 8 {
382            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
383            all_tags.sort_by_key(|f| f.tag);
384            len += tagged_fields_len(&all_tags)?;
385        }
386        Ok(len)
387    }
388}
389#[derive(Debug, Clone, PartialEq)]
390pub struct OffsetCommitRequestPartition {
391    /// The partition index.
392    pub partition_index: i32,
393    /// The message offset to be committed.
394    pub committed_offset: i64,
395    /// The leader epoch of this partition.
396    pub committed_leader_epoch: i32,
397    /// Any associated metadata the client wants to keep.
398    pub committed_metadata: Option<KafkaString>,
399    pub _unknown_tagged_fields: Vec<RawTaggedField>,
400}
401impl Default for OffsetCommitRequestPartition {
402    fn default() -> Self {
403        Self {
404            partition_index: 0_i32,
405            committed_offset: 0_i64,
406            committed_leader_epoch: -1i32,
407            committed_metadata: None,
408            _unknown_tagged_fields: Vec::new(),
409        }
410    }
411}
412impl OffsetCommitRequestPartition {
413    pub fn with_partition_index(mut self, value: i32) -> Self {
414        self.partition_index = value;
415        self
416    }
417    pub fn with_committed_offset(mut self, value: i64) -> Self {
418        self.committed_offset = value;
419        self
420    }
421    pub fn with_committed_leader_epoch(mut self, value: i32) -> Self {
422        self.committed_leader_epoch = value;
423        self
424    }
425    pub fn with_committed_metadata(mut self, value: Option<KafkaString>) -> Self {
426        self.committed_metadata = value;
427        self
428    }
429    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
430        let partition_index;
431        let committed_offset;
432        let mut committed_leader_epoch = -1i32;
433        let committed_metadata;
434        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
435        partition_index = read_i32(buf)?;
436        committed_offset = read_i64(buf)?;
437        if version >= 6 {
438            committed_leader_epoch = read_i32(buf)?;
439        }
440        if version >= 8 {
441            committed_metadata = read_compact_nullable_string(buf)?;
442        } else {
443            committed_metadata = read_nullable_string(buf)?;
444        }
445        if version >= 8 {
446            let tagged_fields = read_tagged_fields(buf)?;
447            for field in &tagged_fields {
448                match field.tag {
449                    _ => {
450                        _unknown_tagged_fields.push(field.clone());
451                    },
452                }
453            }
454        }
455        Ok(Self {
456            partition_index,
457            committed_offset,
458            committed_leader_epoch,
459            committed_metadata,
460            _unknown_tagged_fields,
461        })
462    }
463    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
464        write_i32(buf, self.partition_index);
465        write_i64(buf, self.committed_offset);
466        if version >= 6 {
467            write_i32(buf, self.committed_leader_epoch);
468        } else if self.committed_leader_epoch != -1i32 {
469            return Err(UnsupportedFieldVersion::new(8, "committed_leader_epoch", version).into());
470        }
471        if version >= 8 {
472            write_compact_nullable_string(buf, self.committed_metadata.as_ref())?;
473        } else {
474            write_nullable_string(buf, self.committed_metadata.as_ref())?;
475        }
476        if version >= 8 {
477            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
478            all_tags.sort_by_key(|f| f.tag);
479            write_tagged_fields(buf, &all_tags)?;
480        }
481        Ok(())
482    }
483    pub fn encoded_len(&self, version: i16) -> Result<usize> {
484        let mut len: usize = 0;
485        len += 4;
486        len += 8;
487        if version >= 6 {
488            len += 4;
489        } else if self.committed_leader_epoch != -1i32 {
490            return Err(UnsupportedFieldVersion::new(8, "committed_leader_epoch", version).into());
491        }
492        if version >= 8 {
493            len += compact_nullable_string_len(self.committed_metadata.as_ref())?;
494        } else {
495            len += nullable_string_len(self.committed_metadata.as_ref())?;
496        }
497        if version >= 8 {
498            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
499            all_tags.sort_by_key(|f| f.tag);
500            len += tagged_fields_len(&all_tags)?;
501        }
502        Ok(len)
503    }
504}