Skip to main content

kacrab_protocol/generated/
fetch_snapshot_request.rs

1//! Generated from FetchSnapshotRequest.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 FetchSnapshotRequestData {
17    /// The clusterId if known, this is used to validate metadata fetches prior to broker
18    /// registration.
19    pub cluster_id: Option<KafkaString>,
20    /// The broker ID of the follower.
21    pub replica_id: i32,
22    /// The maximum bytes to fetch from all of the snapshots.
23    pub max_bytes: i32,
24    /// The topics to fetch.
25    pub topics: Vec<TopicSnapshot>,
26    pub _unknown_tagged_fields: Vec<RawTaggedField>,
27}
28impl Default for FetchSnapshotRequestData {
29    fn default() -> Self {
30        Self {
31            cluster_id: None,
32            replica_id: -1i32,
33            max_bytes: i32::MAX,
34            topics: Vec::new(),
35            _unknown_tagged_fields: Vec::new(),
36        }
37    }
38}
39impl FetchSnapshotRequestData {
40    pub fn with_cluster_id(mut self, value: Option<KafkaString>) -> Self {
41        self.cluster_id = value;
42        self
43    }
44    pub fn with_replica_id(mut self, value: i32) -> Self {
45        self.replica_id = value;
46        self
47    }
48    pub fn with_max_bytes(mut self, value: i32) -> Self {
49        self.max_bytes = value;
50        self
51    }
52    pub fn with_topics(mut self, value: Vec<TopicSnapshot>) -> Self {
53        self.topics = value;
54        self
55    }
56    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
57        if version < 0 || version > 1 {
58            return Err(UnsupportedVersion::new(59, version).into());
59        }
60        let mut cluster_id = None;
61        let replica_id;
62        let max_bytes;
63        let topics;
64        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
65        replica_id = read_i32(buf)?;
66        max_bytes = read_i32(buf)?;
67        topics = {
68            let len = read_compact_array_length(buf)?;
69            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
70            for _ in 0..len {
71                arr.push(TopicSnapshot::read(buf, version)?);
72            }
73            arr
74        };
75        let tagged_fields = read_tagged_fields(buf)?;
76        for field in &tagged_fields {
77            match field.tag {
78                0 => {
79                    let mut tag_buf = field.data.clone();
80                    cluster_id = read_compact_nullable_string(&mut tag_buf)?;
81                },
82                _ => {
83                    _unknown_tagged_fields.push(field.clone());
84                },
85            }
86        }
87        Ok(Self {
88            cluster_id,
89            replica_id,
90            max_bytes,
91            topics,
92            _unknown_tagged_fields,
93        })
94    }
95    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
96        if version < 0 || version > 1 {
97            return Err(UnsupportedVersion::new(59, version).into());
98        }
99        write_i32(buf, self.replica_id);
100        write_i32(buf, self.max_bytes);
101        write_compact_array_length(buf, self.topics.len() as i32);
102        for el in &self.topics {
103            el.write(buf, version)?;
104        }
105        let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
106        if self.cluster_id.is_some() {
107            let mut tag_buf = BytesMut::new();
108            write_compact_nullable_string(&mut tag_buf, self.cluster_id.as_ref())?;
109            known_tagged_fields.push(RawTaggedField {
110                tag: 0,
111                data: tag_buf.freeze(),
112            });
113        }
114        let mut all_tags = known_tagged_fields;
115        all_tags.extend(self._unknown_tagged_fields.iter().cloned());
116        all_tags.sort_by_key(|f| f.tag);
117        write_tagged_fields(buf, &all_tags)?;
118        Ok(())
119    }
120    pub fn encoded_len(&self, version: i16) -> Result<usize> {
121        if version < 0 || version > 1 {
122            return Err(UnsupportedVersion::new(59, version).into());
123        }
124        let mut len: usize = 0;
125        len += 4;
126        len += 4;
127        len += compact_array_length_len(self.topics.len() as i32);
128        for el in &self.topics {
129            len += el.encoded_len(version)?;
130        }
131        let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
132        if self.cluster_id.is_some() {
133            let mut tag_buf = BytesMut::new();
134            write_compact_nullable_string(&mut tag_buf, self.cluster_id.as_ref())?;
135            known_tagged_fields.push(RawTaggedField {
136                tag: 0,
137                data: tag_buf.freeze(),
138            });
139        }
140        let mut all_tags = known_tagged_fields;
141        all_tags.extend(self._unknown_tagged_fields.iter().cloned());
142        all_tags.sort_by_key(|f| f.tag);
143        len += tagged_fields_len(&all_tags)?;
144        Ok(len)
145    }
146}
147#[derive(Debug, Clone, PartialEq)]
148pub struct TopicSnapshot {
149    /// The name of the topic to fetch.
150    pub name: KafkaString,
151    /// The partitions to fetch.
152    pub partitions: Vec<PartitionSnapshot>,
153    pub _unknown_tagged_fields: Vec<RawTaggedField>,
154}
155impl Default for TopicSnapshot {
156    fn default() -> Self {
157        Self {
158            name: KafkaString::default(),
159            partitions: Vec::new(),
160            _unknown_tagged_fields: Vec::new(),
161        }
162    }
163}
164impl TopicSnapshot {
165    pub fn with_name(mut self, value: KafkaString) -> Self {
166        self.name = value;
167        self
168    }
169    pub fn with_partitions(mut self, value: Vec<PartitionSnapshot>) -> Self {
170        self.partitions = value;
171        self
172    }
173    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
174        let name;
175        let partitions;
176        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
177        name = read_compact_string(buf)?;
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(PartitionSnapshot::read(buf, version)?);
183            }
184            arr
185        };
186        let tagged_fields = read_tagged_fields(buf)?;
187        for field in &tagged_fields {
188            match field.tag {
189                _ => {
190                    _unknown_tagged_fields.push(field.clone());
191                },
192            }
193        }
194        Ok(Self {
195            name,
196            partitions,
197            _unknown_tagged_fields,
198        })
199    }
200    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
201        write_compact_string(buf, &self.name)?;
202        write_compact_array_length(buf, self.partitions.len() as i32);
203        for el in &self.partitions {
204            el.write(buf, version)?;
205        }
206        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
207        all_tags.sort_by_key(|f| f.tag);
208        write_tagged_fields(buf, &all_tags)?;
209        Ok(())
210    }
211    pub fn encoded_len(&self, version: i16) -> Result<usize> {
212        let mut len: usize = 0;
213        len += compact_string_len(&self.name)?;
214        len += compact_array_length_len(self.partitions.len() as i32);
215        for el in &self.partitions {
216            len += el.encoded_len(version)?;
217        }
218        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
219        all_tags.sort_by_key(|f| f.tag);
220        len += tagged_fields_len(&all_tags)?;
221        Ok(len)
222    }
223}
224#[derive(Debug, Clone, PartialEq)]
225pub struct PartitionSnapshot {
226    /// The partition index.
227    pub partition: i32,
228    /// The current leader epoch of the partition, -1 for unknown leader epoch.
229    pub current_leader_epoch: i32,
230    /// The snapshot endOffset and epoch to fetch.
231    pub snapshot_id: SnapshotId,
232    /// The byte position within the snapshot to start fetching from.
233    pub position: i64,
234    /// The directory id of the follower fetching.
235    pub replica_directory_id: KafkaUuid,
236    pub _unknown_tagged_fields: Vec<RawTaggedField>,
237}
238impl Default for PartitionSnapshot {
239    fn default() -> Self {
240        Self {
241            partition: 0_i32,
242            current_leader_epoch: 0_i32,
243            snapshot_id: SnapshotId::default(),
244            position: 0_i64,
245            replica_directory_id: KafkaUuid::ZERO,
246            _unknown_tagged_fields: Vec::new(),
247        }
248    }
249}
250impl PartitionSnapshot {
251    pub fn with_partition(mut self, value: i32) -> Self {
252        self.partition = value;
253        self
254    }
255    pub fn with_current_leader_epoch(mut self, value: i32) -> Self {
256        self.current_leader_epoch = value;
257        self
258    }
259    pub fn with_snapshot_id(mut self, value: SnapshotId) -> Self {
260        self.snapshot_id = value;
261        self
262    }
263    pub fn with_position(mut self, value: i64) -> Self {
264        self.position = value;
265        self
266    }
267    pub fn with_replica_directory_id(mut self, value: KafkaUuid) -> Self {
268        self.replica_directory_id = value;
269        self
270    }
271    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
272        let partition;
273        let current_leader_epoch;
274        let snapshot_id;
275        let position;
276        let mut replica_directory_id = KafkaUuid::ZERO;
277        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
278        partition = read_i32(buf)?;
279        current_leader_epoch = read_i32(buf)?;
280        snapshot_id = SnapshotId::read(buf, version)?;
281        position = read_i64(buf)?;
282        let tagged_fields = read_tagged_fields(buf)?;
283        for field in &tagged_fields {
284            match field.tag {
285                0 => {
286                    if version >= 1 {
287                        let mut tag_buf = field.data.clone();
288                        replica_directory_id = read_uuid(&mut tag_buf)?;
289                    }
290                },
291                _ => {
292                    _unknown_tagged_fields.push(field.clone());
293                },
294            }
295        }
296        Ok(Self {
297            partition,
298            current_leader_epoch,
299            snapshot_id,
300            position,
301            replica_directory_id,
302            _unknown_tagged_fields,
303        })
304    }
305    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
306        write_i32(buf, self.partition);
307        write_i32(buf, self.current_leader_epoch);
308        self.snapshot_id.write(buf, version)?;
309        write_i64(buf, self.position);
310        let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
311        if version >= 1 && !self.replica_directory_id.is_nil() {
312            let mut tag_buf = BytesMut::new();
313            write_uuid(&mut tag_buf, &self.replica_directory_id);
314            known_tagged_fields.push(RawTaggedField {
315                tag: 0,
316                data: tag_buf.freeze(),
317            });
318        }
319        let mut all_tags = known_tagged_fields;
320        all_tags.extend(self._unknown_tagged_fields.iter().cloned());
321        all_tags.sort_by_key(|f| f.tag);
322        write_tagged_fields(buf, &all_tags)?;
323        Ok(())
324    }
325    pub fn encoded_len(&self, version: i16) -> Result<usize> {
326        let mut len: usize = 0;
327        len += 4;
328        len += 4;
329        len += self.snapshot_id.encoded_len(version)?;
330        len += 8;
331        let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
332        if version >= 1 && !self.replica_directory_id.is_nil() {
333            let mut tag_buf = BytesMut::new();
334            write_uuid(&mut tag_buf, &self.replica_directory_id);
335            known_tagged_fields.push(RawTaggedField {
336                tag: 0,
337                data: tag_buf.freeze(),
338            });
339        }
340        let mut all_tags = known_tagged_fields;
341        all_tags.extend(self._unknown_tagged_fields.iter().cloned());
342        all_tags.sort_by_key(|f| f.tag);
343        len += tagged_fields_len(&all_tags)?;
344        Ok(len)
345    }
346}
347#[derive(Debug, Clone, PartialEq)]
348pub struct SnapshotId {
349    /// The end offset of the snapshot.
350    pub end_offset: i64,
351    /// The epoch of the snapshot.
352    pub epoch: i32,
353    pub _unknown_tagged_fields: Vec<RawTaggedField>,
354}
355impl Default for SnapshotId {
356    fn default() -> Self {
357        Self {
358            end_offset: 0_i64,
359            epoch: 0_i32,
360            _unknown_tagged_fields: Vec::new(),
361        }
362    }
363}
364impl SnapshotId {
365    pub fn with_end_offset(mut self, value: i64) -> Self {
366        self.end_offset = value;
367        self
368    }
369    pub fn with_epoch(mut self, value: i32) -> Self {
370        self.epoch = value;
371        self
372    }
373    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
374        let end_offset;
375        let epoch;
376        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
377        end_offset = read_i64(buf)?;
378        epoch = read_i32(buf)?;
379        let tagged_fields = read_tagged_fields(buf)?;
380        for field in &tagged_fields {
381            match field.tag {
382                _ => {
383                    _unknown_tagged_fields.push(field.clone());
384                },
385            }
386        }
387        Ok(Self {
388            end_offset,
389            epoch,
390            _unknown_tagged_fields,
391        })
392    }
393    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
394        write_i64(buf, self.end_offset);
395        write_i32(buf, self.epoch);
396        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
397        all_tags.sort_by_key(|f| f.tag);
398        write_tagged_fields(buf, &all_tags)?;
399        Ok(())
400    }
401    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
402        let mut len: usize = 0;
403        len += 8;
404        len += 4;
405        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
406        all_tags.sort_by_key(|f| f.tag);
407        len += tagged_fields_len(&all_tags)?;
408        Ok(len)
409    }
410}