Skip to main content

kacrab_protocol/generated/
offset_for_leader_epoch_request.rs

1//! Generated from OffsetForLeaderEpochRequest.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 OffsetForLeaderEpochRequestData {
17    /// The broker ID of the follower, of -1 if this request is from a consumer.
18    pub replica_id: i32,
19    /// Each topic to get offsets for.
20    pub topics: Vec<OffsetForLeaderTopic>,
21    pub _unknown_tagged_fields: Vec<RawTaggedField>,
22}
23impl Default for OffsetForLeaderEpochRequestData {
24    fn default() -> Self {
25        Self {
26            replica_id: -2i32,
27            topics: Vec::new(),
28            _unknown_tagged_fields: Vec::new(),
29        }
30    }
31}
32impl OffsetForLeaderEpochRequestData {
33    pub fn with_replica_id(mut self, value: i32) -> Self {
34        self.replica_id = value;
35        self
36    }
37    pub fn with_topics(mut self, value: Vec<OffsetForLeaderTopic>) -> Self {
38        self.topics = value;
39        self
40    }
41    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
42        if version < 2 || version > 4 {
43            return Err(UnsupportedVersion::new(23, version).into());
44        }
45        let mut replica_id = -2i32;
46        let topics;
47        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
48        if version >= 3 {
49            replica_id = read_i32(buf)?;
50        }
51        if version >= 4 {
52            topics = {
53                let len = read_compact_array_length(buf)?;
54                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
55                for _ in 0..len {
56                    arr.push(OffsetForLeaderTopic::read(buf, version)?);
57                }
58                arr
59            };
60        } else {
61            topics = {
62                let len = read_array_length(buf)?;
63                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
64                for _ in 0..len {
65                    arr.push(OffsetForLeaderTopic::read(buf, version)?);
66                }
67                arr
68            };
69        }
70        if version >= 4 {
71            let tagged_fields = read_tagged_fields(buf)?;
72            for field in &tagged_fields {
73                match field.tag {
74                    _ => {
75                        _unknown_tagged_fields.push(field.clone());
76                    },
77                }
78            }
79        }
80        Ok(Self {
81            replica_id,
82            topics,
83            _unknown_tagged_fields,
84        })
85    }
86    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
87        if version < 2 || version > 4 {
88            return Err(UnsupportedVersion::new(23, version).into());
89        }
90        if version >= 3 {
91            write_i32(buf, self.replica_id);
92        } else if self.replica_id != -2i32 {
93            return Err(UnsupportedFieldVersion::new(23, "replica_id", version).into());
94        }
95        if version >= 4 {
96            write_compact_array_length(buf, self.topics.len() as i32);
97            for el in &self.topics {
98                el.write(buf, version)?;
99            }
100        } else {
101            write_array_length(buf, self.topics.len() as i32);
102            for el in &self.topics {
103                el.write(buf, version)?;
104            }
105        }
106        if version >= 4 {
107            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
108            all_tags.sort_by_key(|f| f.tag);
109            write_tagged_fields(buf, &all_tags)?;
110        }
111        Ok(())
112    }
113    pub fn encoded_len(&self, version: i16) -> Result<usize> {
114        if version < 2 || version > 4 {
115            return Err(UnsupportedVersion::new(23, version).into());
116        }
117        let mut len: usize = 0;
118        if version >= 3 {
119            len += 4;
120        } else if self.replica_id != -2i32 {
121            return Err(UnsupportedFieldVersion::new(23, "replica_id", version).into());
122        }
123        if version >= 4 {
124            len += compact_array_length_len(self.topics.len() as i32);
125            for el in &self.topics {
126                len += el.encoded_len(version)?;
127            }
128        } else {
129            len += array_length_len();
130            for el in &self.topics {
131                len += el.encoded_len(version)?;
132            }
133        }
134        if version >= 4 {
135            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
136            all_tags.sort_by_key(|f| f.tag);
137            len += tagged_fields_len(&all_tags)?;
138        }
139        Ok(len)
140    }
141}
142#[derive(Debug, Clone, PartialEq)]
143pub struct OffsetForLeaderTopic {
144    /// The topic name.
145    pub topic: KafkaString,
146    /// Each partition to get offsets for.
147    pub partitions: Vec<OffsetForLeaderPartition>,
148    pub _unknown_tagged_fields: Vec<RawTaggedField>,
149}
150impl Default for OffsetForLeaderTopic {
151    fn default() -> Self {
152        Self {
153            topic: KafkaString::default(),
154            partitions: Vec::new(),
155            _unknown_tagged_fields: Vec::new(),
156        }
157    }
158}
159impl OffsetForLeaderTopic {
160    pub fn with_topic(mut self, value: KafkaString) -> Self {
161        self.topic = value;
162        self
163    }
164    pub fn with_partitions(mut self, value: Vec<OffsetForLeaderPartition>) -> Self {
165        self.partitions = value;
166        self
167    }
168    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
169        let topic;
170        let partitions;
171        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
172        if version >= 4 {
173            topic = read_compact_string(buf)?;
174        } else {
175            topic = read_string(buf)?;
176        }
177        if version >= 4 {
178            partitions = {
179                let len = read_compact_array_length(buf)?;
180                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
181                for _ in 0..len {
182                    arr.push(OffsetForLeaderPartition::read(buf, version)?);
183                }
184                arr
185            };
186        } else {
187            partitions = {
188                let len = read_array_length(buf)?;
189                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
190                for _ in 0..len {
191                    arr.push(OffsetForLeaderPartition::read(buf, version)?);
192                }
193                arr
194            };
195        }
196        if version >= 4 {
197            let tagged_fields = read_tagged_fields(buf)?;
198            for field in &tagged_fields {
199                match field.tag {
200                    _ => {
201                        _unknown_tagged_fields.push(field.clone());
202                    },
203                }
204            }
205        }
206        Ok(Self {
207            topic,
208            partitions,
209            _unknown_tagged_fields,
210        })
211    }
212    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
213        if version >= 4 {
214            write_compact_string(buf, &self.topic)?;
215        } else {
216            write_string(buf, &self.topic)?;
217        }
218        if version >= 4 {
219            write_compact_array_length(buf, self.partitions.len() as i32);
220            for el in &self.partitions {
221                el.write(buf, version)?;
222            }
223        } else {
224            write_array_length(buf, self.partitions.len() as i32);
225            for el in &self.partitions {
226                el.write(buf, version)?;
227            }
228        }
229        if version >= 4 {
230            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
231            all_tags.sort_by_key(|f| f.tag);
232            write_tagged_fields(buf, &all_tags)?;
233        }
234        Ok(())
235    }
236    pub fn encoded_len(&self, version: i16) -> Result<usize> {
237        let mut len: usize = 0;
238        if version >= 4 {
239            len += compact_string_len(&self.topic)?;
240        } else {
241            len += string_len(&self.topic)?;
242        }
243        if version >= 4 {
244            len += compact_array_length_len(self.partitions.len() as i32);
245            for el in &self.partitions {
246                len += el.encoded_len(version)?;
247            }
248        } else {
249            len += array_length_len();
250            for el in &self.partitions {
251                len += el.encoded_len(version)?;
252            }
253        }
254        if version >= 4 {
255            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
256            all_tags.sort_by_key(|f| f.tag);
257            len += tagged_fields_len(&all_tags)?;
258        }
259        Ok(len)
260    }
261}
262#[derive(Debug, Clone, PartialEq)]
263pub struct OffsetForLeaderPartition {
264    /// The partition index.
265    pub partition: i32,
266    /// An epoch used to fence consumers/replicas with old metadata. If the epoch provided by the
267    /// client is larger than the current epoch known to the broker, then the UNKNOWN_LEADER_EPOCH
268    /// error code will be returned. If the provided epoch is smaller, then the FENCED_LEADER_EPOCH
269    /// error code will be returned.
270    pub current_leader_epoch: i32,
271    /// The epoch to look up an offset for.
272    pub leader_epoch: i32,
273    pub _unknown_tagged_fields: Vec<RawTaggedField>,
274}
275impl Default for OffsetForLeaderPartition {
276    fn default() -> Self {
277        Self {
278            partition: 0_i32,
279            current_leader_epoch: -1i32,
280            leader_epoch: 0_i32,
281            _unknown_tagged_fields: Vec::new(),
282        }
283    }
284}
285impl OffsetForLeaderPartition {
286    pub fn with_partition(mut self, value: i32) -> Self {
287        self.partition = value;
288        self
289    }
290    pub fn with_current_leader_epoch(mut self, value: i32) -> Self {
291        self.current_leader_epoch = value;
292        self
293    }
294    pub fn with_leader_epoch(mut self, value: i32) -> Self {
295        self.leader_epoch = value;
296        self
297    }
298    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
299        let partition;
300        let current_leader_epoch;
301        let leader_epoch;
302        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
303        partition = read_i32(buf)?;
304        current_leader_epoch = read_i32(buf)?;
305        leader_epoch = read_i32(buf)?;
306        if version >= 4 {
307            let tagged_fields = read_tagged_fields(buf)?;
308            for field in &tagged_fields {
309                match field.tag {
310                    _ => {
311                        _unknown_tagged_fields.push(field.clone());
312                    },
313                }
314            }
315        }
316        Ok(Self {
317            partition,
318            current_leader_epoch,
319            leader_epoch,
320            _unknown_tagged_fields,
321        })
322    }
323    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
324        write_i32(buf, self.partition);
325        write_i32(buf, self.current_leader_epoch);
326        write_i32(buf, self.leader_epoch);
327        if version >= 4 {
328            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
329            all_tags.sort_by_key(|f| f.tag);
330            write_tagged_fields(buf, &all_tags)?;
331        }
332        Ok(())
333    }
334    pub fn encoded_len(&self, version: i16) -> Result<usize> {
335        let mut len: usize = 0;
336        len += 4;
337        len += 4;
338        len += 4;
339        if version >= 4 {
340            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
341            all_tags.sort_by_key(|f| f.tag);
342            len += tagged_fields_len(&all_tags)?;
343        }
344        Ok(len)
345    }
346}