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