kacrab_protocol/generated/
elect_leaders_request.rs1#![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 ElectLeadersRequestData {
17 pub election_type: i8,
20 pub topic_partitions: Option<Vec<TopicPartitions>>,
22 pub timeout_ms: i32,
24 pub _unknown_tagged_fields: Vec<RawTaggedField>,
25}
26impl Default for ElectLeadersRequestData {
27 fn default() -> Self {
28 Self {
29 election_type: 0_i8,
30 topic_partitions: None,
31 timeout_ms: 60000i32,
32 _unknown_tagged_fields: Vec::new(),
33 }
34 }
35}
36impl ElectLeadersRequestData {
37 pub fn with_election_type(mut self, value: i8) -> Self {
38 self.election_type = value;
39 self
40 }
41 pub fn with_topic_partitions(mut self, value: Option<Vec<TopicPartitions>>) -> Self {
42 self.topic_partitions = value;
43 self
44 }
45 pub fn with_timeout_ms(mut self, value: i32) -> Self {
46 self.timeout_ms = value;
47 self
48 }
49 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
50 if version < 0 || version > 2 {
51 return Err(UnsupportedVersion::new(43, version).into());
52 }
53 let mut election_type = 0_i8;
54 let topic_partitions;
55 let timeout_ms;
56 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
57 if version >= 1 {
58 election_type = read_i8(buf)?;
59 }
60 if version >= 2 {
61 topic_partitions = {
62 let len = read_compact_array_length(buf)?;
63 if len < 0 {
64 None
65 } else {
66 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
67 for _ in 0..len {
68 arr.push(TopicPartitions::read(buf, version)?);
69 }
70 Some(arr)
71 }
72 };
73 } else {
74 topic_partitions = {
75 let len = read_array_length(buf)?;
76 if len < 0 {
77 None
78 } else {
79 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
80 for _ in 0..len {
81 arr.push(TopicPartitions::read(buf, version)?);
82 }
83 Some(arr)
84 }
85 };
86 }
87 timeout_ms = read_i32(buf)?;
88 if version >= 2 {
89 let tagged_fields = read_tagged_fields(buf)?;
90 for field in &tagged_fields {
91 match field.tag {
92 _ => {
93 _unknown_tagged_fields.push(field.clone());
94 },
95 }
96 }
97 }
98 Ok(Self {
99 election_type,
100 topic_partitions,
101 timeout_ms,
102 _unknown_tagged_fields,
103 })
104 }
105 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
106 if version < 0 || version > 2 {
107 return Err(UnsupportedVersion::new(43, version).into());
108 }
109 if version >= 1 {
110 write_i8(buf, self.election_type);
111 } else if self.election_type != 0_i8 {
112 return Err(UnsupportedFieldVersion::new(43, "election_type", version).into());
113 }
114 if version >= 2 {
115 match &self.topic_partitions {
116 None => {
117 write_compact_array_length(buf, -1);
118 },
119 Some(arr) => {
120 write_compact_array_length(buf, arr.len() as i32);
121 for el in arr {
122 el.write(buf, version)?;
123 }
124 },
125 }
126 } else {
127 match &self.topic_partitions {
128 None => {
129 write_array_length(buf, -1);
130 },
131 Some(arr) => {
132 write_array_length(buf, arr.len() as i32);
133 for el in arr {
134 el.write(buf, version)?;
135 }
136 },
137 }
138 }
139 write_i32(buf, self.timeout_ms);
140 if version >= 2 {
141 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
142 all_tags.sort_by_key(|f| f.tag);
143 write_tagged_fields(buf, &all_tags)?;
144 }
145 Ok(())
146 }
147 pub fn encoded_len(&self, version: i16) -> Result<usize> {
148 if version < 0 || version > 2 {
149 return Err(UnsupportedVersion::new(43, version).into());
150 }
151 let mut len: usize = 0;
152 if version >= 1 {
153 len += 1;
154 } else if self.election_type != 0_i8 {
155 return Err(UnsupportedFieldVersion::new(43, "election_type", version).into());
156 }
157 if version >= 2 {
158 match &self.topic_partitions {
159 None => {
160 len += compact_array_length_len(-1);
161 },
162 Some(arr) => {
163 len += compact_array_length_len(arr.len() as i32);
164 for el in arr {
165 len += el.encoded_len(version)?;
166 }
167 },
168 }
169 } else {
170 match &self.topic_partitions {
171 None => {
172 len += array_length_len();
173 },
174 Some(arr) => {
175 len += array_length_len();
176 for el in arr {
177 len += el.encoded_len(version)?;
178 }
179 },
180 }
181 }
182 len += 4;
183 if version >= 2 {
184 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
185 all_tags.sort_by_key(|f| f.tag);
186 len += tagged_fields_len(&all_tags)?;
187 }
188 Ok(len)
189 }
190}
191#[derive(Debug, Clone, PartialEq)]
192pub struct TopicPartitions {
193 pub topic: KafkaString,
195 pub partitions: Vec<i32>,
197 pub _unknown_tagged_fields: Vec<RawTaggedField>,
198}
199impl Default for TopicPartitions {
200 fn default() -> Self {
201 Self {
202 topic: KafkaString::default(),
203 partitions: Vec::new(),
204 _unknown_tagged_fields: Vec::new(),
205 }
206 }
207}
208impl TopicPartitions {
209 pub fn with_topic(mut self, value: KafkaString) -> Self {
210 self.topic = value;
211 self
212 }
213 pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
214 self.partitions = value;
215 self
216 }
217 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
218 let topic;
219 let partitions;
220 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
221 if version >= 2 {
222 topic = read_compact_string(buf)?;
223 } else {
224 topic = read_string(buf)?;
225 }
226 if version >= 2 {
227 partitions = {
228 let len = read_compact_array_length(buf)?;
229 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
230 for _ in 0..len {
231 arr.push(read_i32(buf)?);
232 }
233 arr
234 };
235 } else {
236 partitions = {
237 let len = read_array_length(buf)?;
238 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
239 for _ in 0..len {
240 arr.push(read_i32(buf)?);
241 }
242 arr
243 };
244 }
245 if version >= 2 {
246 let tagged_fields = read_tagged_fields(buf)?;
247 for field in &tagged_fields {
248 match field.tag {
249 _ => {
250 _unknown_tagged_fields.push(field.clone());
251 },
252 }
253 }
254 }
255 Ok(Self {
256 topic,
257 partitions,
258 _unknown_tagged_fields,
259 })
260 }
261 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
262 if version >= 2 {
263 write_compact_string(buf, &self.topic)?;
264 } else {
265 write_string(buf, &self.topic)?;
266 }
267 if version >= 2 {
268 write_compact_array_length(buf, self.partitions.len() as i32);
269 for el in &self.partitions {
270 write_i32(buf, *el);
271 }
272 } else {
273 write_array_length(buf, self.partitions.len() as i32);
274 for el in &self.partitions {
275 write_i32(buf, *el);
276 }
277 }
278 if version >= 2 {
279 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
280 all_tags.sort_by_key(|f| f.tag);
281 write_tagged_fields(buf, &all_tags)?;
282 }
283 Ok(())
284 }
285 pub fn encoded_len(&self, version: i16) -> Result<usize> {
286 let mut len: usize = 0;
287 if version >= 2 {
288 len += compact_string_len(&self.topic)?;
289 } else {
290 len += string_len(&self.topic)?;
291 }
292 if version >= 2 {
293 len += compact_array_length_len(self.partitions.len() as i32);
294 len += self.partitions.len() * 4usize;
295 } else {
296 len += array_length_len();
297 len += self.partitions.len() * 4usize;
298 }
299 if version >= 2 {
300 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
301 all_tags.sort_by_key(|f| f.tag);
302 len += tagged_fields_len(&all_tags)?;
303 }
304 Ok(len)
305 }
306}