Skip to main content

kacrab_protocol/generated/
describe_quorum_request.rs

1//! Generated from DescribeQuorumRequest.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 DescribeQuorumRequestData {
17    /// The topics to describe.
18    pub topics: Vec<TopicData>,
19    pub _unknown_tagged_fields: Vec<RawTaggedField>,
20}
21impl Default for DescribeQuorumRequestData {
22    fn default() -> Self {
23        Self {
24            topics: Vec::new(),
25            _unknown_tagged_fields: Vec::new(),
26        }
27    }
28}
29impl DescribeQuorumRequestData {
30    pub fn with_topics(mut self, value: Vec<TopicData>) -> Self {
31        self.topics = value;
32        self
33    }
34    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
35        if version < 0 || version > 2 {
36            return Err(UnsupportedVersion::new(55, version).into());
37        }
38        let topics;
39        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
40        topics = {
41            let len = read_compact_array_length(buf)?;
42            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
43            for _ in 0..len {
44                arr.push(TopicData::read(buf, version)?);
45            }
46            arr
47        };
48        let tagged_fields = read_tagged_fields(buf)?;
49        for field in &tagged_fields {
50            match field.tag {
51                _ => {
52                    _unknown_tagged_fields.push(field.clone());
53                },
54            }
55        }
56        Ok(Self {
57            topics,
58            _unknown_tagged_fields,
59        })
60    }
61    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
62        if version < 0 || version > 2 {
63            return Err(UnsupportedVersion::new(55, version).into());
64        }
65        write_compact_array_length(buf, self.topics.len() as i32);
66        for el in &self.topics {
67            el.write(buf, version)?;
68        }
69        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
70        all_tags.sort_by_key(|f| f.tag);
71        write_tagged_fields(buf, &all_tags)?;
72        Ok(())
73    }
74    pub fn encoded_len(&self, version: i16) -> Result<usize> {
75        if version < 0 || version > 2 {
76            return Err(UnsupportedVersion::new(55, version).into());
77        }
78        let mut len: usize = 0;
79        len += compact_array_length_len(self.topics.len() as i32);
80        for el in &self.topics {
81            len += el.encoded_len(version)?;
82        }
83        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
84        all_tags.sort_by_key(|f| f.tag);
85        len += tagged_fields_len(&all_tags)?;
86        Ok(len)
87    }
88}
89#[derive(Debug, Clone, PartialEq)]
90pub struct TopicData {
91    /// The topic name.
92    pub topic_name: KafkaString,
93    /// The partitions to describe.
94    pub partitions: Vec<PartitionData>,
95    pub _unknown_tagged_fields: Vec<RawTaggedField>,
96}
97impl Default for TopicData {
98    fn default() -> Self {
99        Self {
100            topic_name: KafkaString::default(),
101            partitions: Vec::new(),
102            _unknown_tagged_fields: Vec::new(),
103        }
104    }
105}
106impl TopicData {
107    pub fn with_topic_name(mut self, value: KafkaString) -> Self {
108        self.topic_name = value;
109        self
110    }
111    pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
112        self.partitions = value;
113        self
114    }
115    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
116        let topic_name;
117        let partitions;
118        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
119        topic_name = read_compact_string(buf)?;
120        partitions = {
121            let len = read_compact_array_length(buf)?;
122            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
123            for _ in 0..len {
124                arr.push(PartitionData::read(buf, version)?);
125            }
126            arr
127        };
128        let tagged_fields = read_tagged_fields(buf)?;
129        for field in &tagged_fields {
130            match field.tag {
131                _ => {
132                    _unknown_tagged_fields.push(field.clone());
133                },
134            }
135        }
136        Ok(Self {
137            topic_name,
138            partitions,
139            _unknown_tagged_fields,
140        })
141    }
142    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
143        write_compact_string(buf, &self.topic_name)?;
144        write_compact_array_length(buf, self.partitions.len() as i32);
145        for el in &self.partitions {
146            el.write(buf, version)?;
147        }
148        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
149        all_tags.sort_by_key(|f| f.tag);
150        write_tagged_fields(buf, &all_tags)?;
151        Ok(())
152    }
153    pub fn encoded_len(&self, version: i16) -> Result<usize> {
154        let mut len: usize = 0;
155        len += compact_string_len(&self.topic_name)?;
156        len += compact_array_length_len(self.partitions.len() as i32);
157        for el in &self.partitions {
158            len += el.encoded_len(version)?;
159        }
160        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
161        all_tags.sort_by_key(|f| f.tag);
162        len += tagged_fields_len(&all_tags)?;
163        Ok(len)
164    }
165}
166#[derive(Debug, Clone, PartialEq)]
167pub struct PartitionData {
168    /// The partition index.
169    pub partition_index: i32,
170    pub _unknown_tagged_fields: Vec<RawTaggedField>,
171}
172impl Default for PartitionData {
173    fn default() -> Self {
174        Self {
175            partition_index: 0_i32,
176            _unknown_tagged_fields: Vec::new(),
177        }
178    }
179}
180impl PartitionData {
181    pub fn with_partition_index(mut self, value: i32) -> Self {
182        self.partition_index = value;
183        self
184    }
185    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
186        let partition_index;
187        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
188        partition_index = read_i32(buf)?;
189        let tagged_fields = read_tagged_fields(buf)?;
190        for field in &tagged_fields {
191            match field.tag {
192                _ => {
193                    _unknown_tagged_fields.push(field.clone());
194                },
195            }
196        }
197        Ok(Self {
198            partition_index,
199            _unknown_tagged_fields,
200        })
201    }
202    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
203        write_i32(buf, self.partition_index);
204        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
205        all_tags.sort_by_key(|f| f.tag);
206        write_tagged_fields(buf, &all_tags)?;
207        Ok(())
208    }
209    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
210        let mut len: usize = 0;
211        len += 4;
212        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
213        all_tags.sort_by_key(|f| f.tag);
214        len += tagged_fields_len(&all_tags)?;
215        Ok(len)
216    }
217}