Skip to main content

kacrab_protocol/generated/
fetch_snapshot_response.rs

1//! Generated from FetchSnapshotResponse.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 FetchSnapshotResponseData {
17    /// The duration in milliseconds for which the request was throttled due to a quota violation,
18    /// or zero if the request did not violate any quota.
19    pub throttle_time_ms: i32,
20    /// The top level response error code.
21    pub error_code: i16,
22    /// The topics to fetch.
23    pub topics: Vec<TopicSnapshot>,
24    /// Endpoints for all current-leaders enumerated in PartitionSnapshot.
25    pub node_endpoints: Vec<NodeEndpoint>,
26    pub _unknown_tagged_fields: Vec<RawTaggedField>,
27}
28impl Default for FetchSnapshotResponseData {
29    fn default() -> Self {
30        Self {
31            throttle_time_ms: 0_i32,
32            error_code: 0_i16,
33            topics: Vec::new(),
34            node_endpoints: Vec::new(),
35            _unknown_tagged_fields: Vec::new(),
36        }
37    }
38}
39impl FetchSnapshotResponseData {
40    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
41        self.throttle_time_ms = value;
42        self
43    }
44    pub fn with_error_code(mut self, value: i16) -> Self {
45        self.error_code = value;
46        self
47    }
48    pub fn with_topics(mut self, value: Vec<TopicSnapshot>) -> Self {
49        self.topics = value;
50        self
51    }
52    pub fn with_node_endpoints(mut self, value: Vec<NodeEndpoint>) -> Self {
53        self.node_endpoints = 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 throttle_time_ms;
61        let error_code;
62        let topics;
63        let mut node_endpoints = Vec::new();
64        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
65        throttle_time_ms = read_i32(buf)?;
66        error_code = read_i16(buf)?;
67        topics = {
68            let len = read_compact_array_length(buf)?;
69            let mut arr = Vec::with_capacity(len.max(0) as usize);
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                    if version >= 1 {
80                        let mut tag_buf = field.data.clone();
81                        node_endpoints = {
82                            let len = read_compact_array_length(&mut tag_buf)?;
83                            let mut arr = Vec::with_capacity(len.max(0) as usize);
84                            for _ in 0..len {
85                                arr.push(NodeEndpoint::read(&mut tag_buf, version)?);
86                            }
87                            arr
88                        };
89                    }
90                },
91                _ => {
92                    _unknown_tagged_fields.push(field.clone());
93                },
94            }
95        }
96        Ok(Self {
97            throttle_time_ms,
98            error_code,
99            topics,
100            node_endpoints,
101            _unknown_tagged_fields,
102        })
103    }
104    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
105        if version < 0 || version > 1 {
106            return Err(UnsupportedVersion::new(59, version).into());
107        }
108        write_i32(buf, self.throttle_time_ms);
109        write_i16(buf, self.error_code);
110        write_compact_array_length(buf, self.topics.len() as i32);
111        for el in &self.topics {
112            el.write(buf, version)?;
113        }
114        let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
115        if version >= 1 && !self.node_endpoints.is_empty() {
116            let mut tag_buf = BytesMut::new();
117            write_compact_array_length(&mut tag_buf, self.node_endpoints.len() as i32);
118            for el in &self.node_endpoints {
119                el.write(&mut tag_buf, version)?;
120            }
121            known_tagged_fields.push(RawTaggedField {
122                tag: 0,
123                data: tag_buf.freeze(),
124            });
125        }
126        let mut all_tags = known_tagged_fields;
127        all_tags.extend(self._unknown_tagged_fields.iter().cloned());
128        all_tags.sort_by_key(|f| f.tag);
129        write_tagged_fields(buf, &all_tags)?;
130        Ok(())
131    }
132    pub fn encoded_len(&self, version: i16) -> Result<usize> {
133        if version < 0 || version > 1 {
134            return Err(UnsupportedVersion::new(59, version).into());
135        }
136        let mut len: usize = 0;
137        len += 4;
138        len += 2;
139        len += compact_array_length_len(self.topics.len() as i32);
140        for el in &self.topics {
141            len += el.encoded_len(version)?;
142        }
143        let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
144        if version >= 1 && !self.node_endpoints.is_empty() {
145            let mut tag_buf = BytesMut::new();
146            write_compact_array_length(&mut tag_buf, self.node_endpoints.len() as i32);
147            for el in &self.node_endpoints {
148                el.write(&mut tag_buf, version)?;
149            }
150            known_tagged_fields.push(RawTaggedField {
151                tag: 0,
152                data: tag_buf.freeze(),
153            });
154        }
155        let mut all_tags = known_tagged_fields;
156        all_tags.extend(self._unknown_tagged_fields.iter().cloned());
157        all_tags.sort_by_key(|f| f.tag);
158        len += tagged_fields_len(&all_tags)?;
159        Ok(len)
160    }
161}
162#[derive(Debug, Clone, PartialEq)]
163pub struct TopicSnapshot {
164    /// The name of the topic to fetch.
165    pub name: KafkaString,
166    /// The partitions to fetch.
167    pub partitions: Vec<PartitionSnapshot>,
168    pub _unknown_tagged_fields: Vec<RawTaggedField>,
169}
170impl Default for TopicSnapshot {
171    fn default() -> Self {
172        Self {
173            name: KafkaString::default(),
174            partitions: Vec::new(),
175            _unknown_tagged_fields: Vec::new(),
176        }
177    }
178}
179impl TopicSnapshot {
180    pub fn with_name(mut self, value: KafkaString) -> Self {
181        self.name = value;
182        self
183    }
184    pub fn with_partitions(mut self, value: Vec<PartitionSnapshot>) -> Self {
185        self.partitions = value;
186        self
187    }
188    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
189        let name;
190        let partitions;
191        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
192        name = read_compact_string(buf)?;
193        partitions = {
194            let len = read_compact_array_length(buf)?;
195            let mut arr = Vec::with_capacity(len.max(0) as usize);
196            for _ in 0..len {
197                arr.push(PartitionSnapshot::read(buf, version)?);
198            }
199            arr
200        };
201        let tagged_fields = read_tagged_fields(buf)?;
202        for field in &tagged_fields {
203            match field.tag {
204                _ => {
205                    _unknown_tagged_fields.push(field.clone());
206                },
207            }
208        }
209        Ok(Self {
210            name,
211            partitions,
212            _unknown_tagged_fields,
213        })
214    }
215    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
216        write_compact_string(buf, &self.name)?;
217        write_compact_array_length(buf, self.partitions.len() as i32);
218        for el in &self.partitions {
219            el.write(buf, version)?;
220        }
221        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
222        all_tags.sort_by_key(|f| f.tag);
223        write_tagged_fields(buf, &all_tags)?;
224        Ok(())
225    }
226    pub fn encoded_len(&self, version: i16) -> Result<usize> {
227        let mut len: usize = 0;
228        len += compact_string_len(&self.name)?;
229        len += compact_array_length_len(self.partitions.len() as i32);
230        for el in &self.partitions {
231            len += el.encoded_len(version)?;
232        }
233        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
234        all_tags.sort_by_key(|f| f.tag);
235        len += tagged_fields_len(&all_tags)?;
236        Ok(len)
237    }
238}
239#[derive(Debug, Clone, PartialEq)]
240pub struct PartitionSnapshot {
241    /// The partition index.
242    pub index: i32,
243    /// The error code, or 0 if there was no fetch error.
244    pub error_code: i16,
245    /// The snapshot endOffset and epoch fetched.
246    pub snapshot_id: SnapshotId,
247    /// The leader of the partition at the time of the snapshot.
248    pub current_leader: LeaderIdAndEpoch,
249    /// The total size of the snapshot.
250    pub size: i64,
251    /// The starting byte position within the snapshot included in the Bytes field.
252    pub position: i64,
253    /// Snapshot data in records format which may not be aligned on an offset boundary.
254    pub unaligned_records: Option<Bytes>,
255    pub _unknown_tagged_fields: Vec<RawTaggedField>,
256}
257impl Default for PartitionSnapshot {
258    fn default() -> Self {
259        Self {
260            index: 0_i32,
261            error_code: 0_i16,
262            snapshot_id: SnapshotId::default(),
263            current_leader: LeaderIdAndEpoch::default(),
264            size: 0_i64,
265            position: 0_i64,
266            unaligned_records: None,
267            _unknown_tagged_fields: Vec::new(),
268        }
269    }
270}
271impl PartitionSnapshot {
272    pub fn with_index(mut self, value: i32) -> Self {
273        self.index = value;
274        self
275    }
276    pub fn with_error_code(mut self, value: i16) -> Self {
277        self.error_code = value;
278        self
279    }
280    pub fn with_snapshot_id(mut self, value: SnapshotId) -> Self {
281        self.snapshot_id = value;
282        self
283    }
284    pub fn with_current_leader(mut self, value: LeaderIdAndEpoch) -> Self {
285        self.current_leader = value;
286        self
287    }
288    pub fn with_size(mut self, value: i64) -> Self {
289        self.size = value;
290        self
291    }
292    pub fn with_position(mut self, value: i64) -> Self {
293        self.position = value;
294        self
295    }
296    pub fn with_unaligned_records(mut self, value: Option<Bytes>) -> Self {
297        self.unaligned_records = value;
298        self
299    }
300    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
301        let index;
302        let error_code;
303        let snapshot_id;
304        let mut current_leader = LeaderIdAndEpoch::default();
305        let size;
306        let position;
307        let unaligned_records;
308        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
309        index = read_i32(buf)?;
310        error_code = read_i16(buf)?;
311        snapshot_id = SnapshotId::read(buf, version)?;
312        size = read_i64(buf)?;
313        position = read_i64(buf)?;
314        unaligned_records = read_compact_nullable_bytes(buf)?;
315        let tagged_fields = read_tagged_fields(buf)?;
316        for field in &tagged_fields {
317            match field.tag {
318                0 => {
319                    let mut tag_buf = field.data.clone();
320                    current_leader = LeaderIdAndEpoch::read(&mut tag_buf, version)?;
321                },
322                _ => {
323                    _unknown_tagged_fields.push(field.clone());
324                },
325            }
326        }
327        Ok(Self {
328            index,
329            error_code,
330            snapshot_id,
331            current_leader,
332            size,
333            position,
334            unaligned_records,
335            _unknown_tagged_fields,
336        })
337    }
338    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
339        write_i32(buf, self.index);
340        write_i16(buf, self.error_code);
341        self.snapshot_id.write(buf, version)?;
342        write_i64(buf, self.size);
343        write_i64(buf, self.position);
344        write_compact_nullable_bytes(buf, self.unaligned_records.as_ref().map(|b| b.as_ref()))?;
345        let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
346        if self.current_leader != LeaderIdAndEpoch::default() {
347            let mut tag_buf = BytesMut::new();
348            self.current_leader.write(&mut tag_buf, version)?;
349            known_tagged_fields.push(RawTaggedField {
350                tag: 0,
351                data: tag_buf.freeze(),
352            });
353        }
354        let mut all_tags = known_tagged_fields;
355        all_tags.extend(self._unknown_tagged_fields.iter().cloned());
356        all_tags.sort_by_key(|f| f.tag);
357        write_tagged_fields(buf, &all_tags)?;
358        Ok(())
359    }
360    pub fn encoded_len(&self, version: i16) -> Result<usize> {
361        let mut len: usize = 0;
362        len += 4;
363        len += 2;
364        len += self.snapshot_id.encoded_len(version)?;
365        len += 8;
366        len += 8;
367        len += compact_nullable_bytes_len(self.unaligned_records.as_ref().map(|b| b.as_ref()))?;
368        let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
369        if self.current_leader != LeaderIdAndEpoch::default() {
370            let mut tag_buf = BytesMut::new();
371            self.current_leader.write(&mut tag_buf, version)?;
372            known_tagged_fields.push(RawTaggedField {
373                tag: 0,
374                data: tag_buf.freeze(),
375            });
376        }
377        let mut all_tags = known_tagged_fields;
378        all_tags.extend(self._unknown_tagged_fields.iter().cloned());
379        all_tags.sort_by_key(|f| f.tag);
380        len += tagged_fields_len(&all_tags)?;
381        Ok(len)
382    }
383}
384#[derive(Debug, Clone, PartialEq)]
385pub struct SnapshotId {
386    /// The snapshot end offset.
387    pub end_offset: i64,
388    /// The snapshot epoch.
389    pub epoch: i32,
390    pub _unknown_tagged_fields: Vec<RawTaggedField>,
391}
392impl Default for SnapshotId {
393    fn default() -> Self {
394        Self {
395            end_offset: 0_i64,
396            epoch: 0_i32,
397            _unknown_tagged_fields: Vec::new(),
398        }
399    }
400}
401impl SnapshotId {
402    pub fn with_end_offset(mut self, value: i64) -> Self {
403        self.end_offset = value;
404        self
405    }
406    pub fn with_epoch(mut self, value: i32) -> Self {
407        self.epoch = value;
408        self
409    }
410    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
411        let end_offset;
412        let epoch;
413        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
414        end_offset = read_i64(buf)?;
415        epoch = read_i32(buf)?;
416        let tagged_fields = read_tagged_fields(buf)?;
417        for field in &tagged_fields {
418            match field.tag {
419                _ => {
420                    _unknown_tagged_fields.push(field.clone());
421                },
422            }
423        }
424        Ok(Self {
425            end_offset,
426            epoch,
427            _unknown_tagged_fields,
428        })
429    }
430    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
431        write_i64(buf, self.end_offset);
432        write_i32(buf, self.epoch);
433        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
434        all_tags.sort_by_key(|f| f.tag);
435        write_tagged_fields(buf, &all_tags)?;
436        Ok(())
437    }
438    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
439        let mut len: usize = 0;
440        len += 8;
441        len += 4;
442        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
443        all_tags.sort_by_key(|f| f.tag);
444        len += tagged_fields_len(&all_tags)?;
445        Ok(len)
446    }
447}
448#[derive(Debug, Clone, PartialEq)]
449pub struct LeaderIdAndEpoch {
450    /// The ID of the current leader or -1 if the leader is unknown.
451    pub leader_id: i32,
452    /// The latest known leader epoch.
453    pub leader_epoch: i32,
454    pub _unknown_tagged_fields: Vec<RawTaggedField>,
455}
456impl Default for LeaderIdAndEpoch {
457    fn default() -> Self {
458        Self {
459            leader_id: 0_i32,
460            leader_epoch: 0_i32,
461            _unknown_tagged_fields: Vec::new(),
462        }
463    }
464}
465impl LeaderIdAndEpoch {
466    pub fn with_leader_id(mut self, value: i32) -> Self {
467        self.leader_id = value;
468        self
469    }
470    pub fn with_leader_epoch(mut self, value: i32) -> Self {
471        self.leader_epoch = value;
472        self
473    }
474    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
475        let leader_id;
476        let leader_epoch;
477        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
478        leader_id = read_i32(buf)?;
479        leader_epoch = read_i32(buf)?;
480        let tagged_fields = read_tagged_fields(buf)?;
481        for field in &tagged_fields {
482            match field.tag {
483                _ => {
484                    _unknown_tagged_fields.push(field.clone());
485                },
486            }
487        }
488        Ok(Self {
489            leader_id,
490            leader_epoch,
491            _unknown_tagged_fields,
492        })
493    }
494    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
495        write_i32(buf, self.leader_id);
496        write_i32(buf, self.leader_epoch);
497        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
498        all_tags.sort_by_key(|f| f.tag);
499        write_tagged_fields(buf, &all_tags)?;
500        Ok(())
501    }
502    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
503        let mut len: usize = 0;
504        len += 4;
505        len += 4;
506        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
507        all_tags.sort_by_key(|f| f.tag);
508        len += tagged_fields_len(&all_tags)?;
509        Ok(len)
510    }
511}
512#[derive(Debug, Clone, PartialEq)]
513pub struct NodeEndpoint {
514    /// The ID of the associated node.
515    pub node_id: i32,
516    /// The node's hostname.
517    pub host: KafkaString,
518    /// The node's port.
519    pub port: u16,
520    pub _unknown_tagged_fields: Vec<RawTaggedField>,
521}
522impl Default for NodeEndpoint {
523    fn default() -> Self {
524        Self {
525            node_id: 0_i32,
526            host: KafkaString::default(),
527            port: 0_u16,
528            _unknown_tagged_fields: Vec::new(),
529        }
530    }
531}
532impl NodeEndpoint {
533    pub fn with_node_id(mut self, value: i32) -> Self {
534        self.node_id = value;
535        self
536    }
537    pub fn with_host(mut self, value: KafkaString) -> Self {
538        self.host = value;
539        self
540    }
541    pub fn with_port(mut self, value: u16) -> Self {
542        self.port = value;
543        self
544    }
545    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
546        let node_id;
547        let host;
548        let port;
549        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
550        node_id = read_i32(buf)?;
551        host = read_compact_string(buf)?;
552        port = read_u16(buf)?;
553        let tagged_fields = read_tagged_fields(buf)?;
554        for field in &tagged_fields {
555            match field.tag {
556                _ => {
557                    _unknown_tagged_fields.push(field.clone());
558                },
559            }
560        }
561        Ok(Self {
562            node_id,
563            host,
564            port,
565            _unknown_tagged_fields,
566        })
567    }
568    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
569        write_i32(buf, self.node_id);
570        write_compact_string(buf, &self.host)?;
571        write_u16(buf, self.port);
572        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
573        all_tags.sort_by_key(|f| f.tag);
574        write_tagged_fields(buf, &all_tags)?;
575        Ok(())
576    }
577    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
578        let mut len: usize = 0;
579        len += 4;
580        len += compact_string_len(&self.host)?;
581        len += 2;
582        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
583        all_tags.sort_by_key(|f| f.tag);
584        len += tagged_fields_len(&all_tags)?;
585        Ok(len)
586    }
587}