kacrab_protocol/generated/
vote_response.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 VoteResponseData {
17 pub error_code: i16,
19 pub topics: Vec<TopicData>,
21 pub node_endpoints: Vec<NodeEndpoint>,
23 pub _unknown_tagged_fields: Vec<RawTaggedField>,
24}
25impl Default for VoteResponseData {
26 fn default() -> Self {
27 Self {
28 error_code: 0_i16,
29 topics: Vec::new(),
30 node_endpoints: Vec::new(),
31 _unknown_tagged_fields: Vec::new(),
32 }
33 }
34}
35impl VoteResponseData {
36 pub fn with_error_code(mut self, value: i16) -> Self {
37 self.error_code = value;
38 self
39 }
40 pub fn with_topics(mut self, value: Vec<TopicData>) -> Self {
41 self.topics = value;
42 self
43 }
44 pub fn with_node_endpoints(mut self, value: Vec<NodeEndpoint>) -> Self {
45 self.node_endpoints = value;
46 self
47 }
48 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
49 if version < 0 || version > 2 {
50 return Err(UnsupportedVersion::new(52, version).into());
51 }
52 let error_code;
53 let topics;
54 let mut node_endpoints = Vec::new();
55 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
56 error_code = read_i16(buf)?;
57 topics = {
58 let len = read_compact_array_length(buf)?;
59 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
60 for _ in 0..len {
61 arr.push(TopicData::read(buf, version)?);
62 }
63 arr
64 };
65 let tagged_fields = read_tagged_fields(buf)?;
66 for field in &tagged_fields {
67 match field.tag {
68 0 => {
69 if version >= 1 {
70 let mut tag_buf = field.data.clone();
71 node_endpoints = {
72 let len = read_compact_array_length(&mut tag_buf)?;
73 let mut arr =
74 Vec::with_capacity(array_read_capacity(len, (&mut tag_buf).len()));
75 for _ in 0..len {
76 arr.push(NodeEndpoint::read(&mut tag_buf, version)?);
77 }
78 arr
79 };
80 }
81 },
82 _ => {
83 _unknown_tagged_fields.push(field.clone());
84 },
85 }
86 }
87 Ok(Self {
88 error_code,
89 topics,
90 node_endpoints,
91 _unknown_tagged_fields,
92 })
93 }
94 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
95 if version < 0 || version > 2 {
96 return Err(UnsupportedVersion::new(52, version).into());
97 }
98 write_i16(buf, self.error_code);
99 write_compact_array_length(buf, self.topics.len() as i32);
100 for el in &self.topics {
101 el.write(buf, version)?;
102 }
103 let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
104 if version >= 1 && !self.node_endpoints.is_empty() {
105 let mut tag_buf = BytesMut::new();
106 write_compact_array_length(&mut tag_buf, self.node_endpoints.len() as i32);
107 for el in &self.node_endpoints {
108 el.write(&mut tag_buf, version)?;
109 }
110 known_tagged_fields.push(RawTaggedField {
111 tag: 0,
112 data: tag_buf.freeze(),
113 });
114 }
115 let mut all_tags = known_tagged_fields;
116 all_tags.extend(self._unknown_tagged_fields.iter().cloned());
117 all_tags.sort_by_key(|f| f.tag);
118 write_tagged_fields(buf, &all_tags)?;
119 Ok(())
120 }
121 pub fn encoded_len(&self, version: i16) -> Result<usize> {
122 if version < 0 || version > 2 {
123 return Err(UnsupportedVersion::new(52, version).into());
124 }
125 let mut len: usize = 0;
126 len += 2;
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 version >= 1 && !self.node_endpoints.is_empty() {
133 let mut tag_buf = BytesMut::new();
134 write_compact_array_length(&mut tag_buf, self.node_endpoints.len() as i32);
135 for el in &self.node_endpoints {
136 el.write(&mut tag_buf, version)?;
137 }
138 known_tagged_fields.push(RawTaggedField {
139 tag: 0,
140 data: tag_buf.freeze(),
141 });
142 }
143 let mut all_tags = known_tagged_fields;
144 all_tags.extend(self._unknown_tagged_fields.iter().cloned());
145 all_tags.sort_by_key(|f| f.tag);
146 len += tagged_fields_len(&all_tags)?;
147 Ok(len)
148 }
149}
150#[derive(Debug, Clone, PartialEq)]
151pub struct TopicData {
152 pub topic_name: KafkaString,
154 pub partitions: Vec<PartitionData>,
156 pub _unknown_tagged_fields: Vec<RawTaggedField>,
157}
158impl Default for TopicData {
159 fn default() -> Self {
160 Self {
161 topic_name: KafkaString::default(),
162 partitions: Vec::new(),
163 _unknown_tagged_fields: Vec::new(),
164 }
165 }
166}
167impl TopicData {
168 pub fn with_topic_name(mut self, value: KafkaString) -> Self {
169 self.topic_name = value;
170 self
171 }
172 pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
173 self.partitions = value;
174 self
175 }
176 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
177 let topic_name;
178 let partitions;
179 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
180 topic_name = read_compact_string(buf)?;
181 partitions = {
182 let len = read_compact_array_length(buf)?;
183 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
184 for _ in 0..len {
185 arr.push(PartitionData::read(buf, version)?);
186 }
187 arr
188 };
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 topic_name,
199 partitions,
200 _unknown_tagged_fields,
201 })
202 }
203 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
204 write_compact_string(buf, &self.topic_name)?;
205 write_compact_array_length(buf, self.partitions.len() as i32);
206 for el in &self.partitions {
207 el.write(buf, version)?;
208 }
209 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
210 all_tags.sort_by_key(|f| f.tag);
211 write_tagged_fields(buf, &all_tags)?;
212 Ok(())
213 }
214 pub fn encoded_len(&self, version: i16) -> Result<usize> {
215 let mut len: usize = 0;
216 len += compact_string_len(&self.topic_name)?;
217 len += compact_array_length_len(self.partitions.len() as i32);
218 for el in &self.partitions {
219 len += el.encoded_len(version)?;
220 }
221 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
222 all_tags.sort_by_key(|f| f.tag);
223 len += tagged_fields_len(&all_tags)?;
224 Ok(len)
225 }
226}
227#[derive(Debug, Clone, PartialEq)]
228pub struct PartitionData {
229 pub partition_index: i32,
231 pub error_code: i16,
233 pub leader_id: i32,
235 pub leader_epoch: i32,
237 pub vote_granted: bool,
239 pub _unknown_tagged_fields: Vec<RawTaggedField>,
240}
241impl Default for PartitionData {
242 fn default() -> Self {
243 Self {
244 partition_index: 0_i32,
245 error_code: 0_i16,
246 leader_id: 0_i32,
247 leader_epoch: 0_i32,
248 vote_granted: false,
249 _unknown_tagged_fields: Vec::new(),
250 }
251 }
252}
253impl PartitionData {
254 pub fn with_partition_index(mut self, value: i32) -> Self {
255 self.partition_index = value;
256 self
257 }
258 pub fn with_error_code(mut self, value: i16) -> Self {
259 self.error_code = value;
260 self
261 }
262 pub fn with_leader_id(mut self, value: i32) -> Self {
263 self.leader_id = value;
264 self
265 }
266 pub fn with_leader_epoch(mut self, value: i32) -> Self {
267 self.leader_epoch = value;
268 self
269 }
270 pub fn with_vote_granted(mut self, value: bool) -> Self {
271 self.vote_granted = value;
272 self
273 }
274 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
275 let partition_index;
276 let error_code;
277 let leader_id;
278 let leader_epoch;
279 let vote_granted;
280 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
281 partition_index = read_i32(buf)?;
282 error_code = read_i16(buf)?;
283 leader_id = read_i32(buf)?;
284 leader_epoch = read_i32(buf)?;
285 vote_granted = read_bool(buf)?;
286 let tagged_fields = read_tagged_fields(buf)?;
287 for field in &tagged_fields {
288 match field.tag {
289 _ => {
290 _unknown_tagged_fields.push(field.clone());
291 },
292 }
293 }
294 Ok(Self {
295 partition_index,
296 error_code,
297 leader_id,
298 leader_epoch,
299 vote_granted,
300 _unknown_tagged_fields,
301 })
302 }
303 pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
304 write_i32(buf, self.partition_index);
305 write_i16(buf, self.error_code);
306 write_i32(buf, self.leader_id);
307 write_i32(buf, self.leader_epoch);
308 write_bool(buf, self.vote_granted);
309 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
310 all_tags.sort_by_key(|f| f.tag);
311 write_tagged_fields(buf, &all_tags)?;
312 Ok(())
313 }
314 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
315 let mut len: usize = 0;
316 len += 4;
317 len += 2;
318 len += 4;
319 len += 4;
320 len += 1;
321 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
322 all_tags.sort_by_key(|f| f.tag);
323 len += tagged_fields_len(&all_tags)?;
324 Ok(len)
325 }
326}
327#[derive(Debug, Clone, PartialEq)]
328pub struct NodeEndpoint {
329 pub node_id: i32,
331 pub host: KafkaString,
333 pub port: u16,
335 pub _unknown_tagged_fields: Vec<RawTaggedField>,
336}
337impl Default for NodeEndpoint {
338 fn default() -> Self {
339 Self {
340 node_id: 0_i32,
341 host: KafkaString::default(),
342 port: 0_u16,
343 _unknown_tagged_fields: Vec::new(),
344 }
345 }
346}
347impl NodeEndpoint {
348 pub fn with_node_id(mut self, value: i32) -> Self {
349 self.node_id = value;
350 self
351 }
352 pub fn with_host(mut self, value: KafkaString) -> Self {
353 self.host = value;
354 self
355 }
356 pub fn with_port(mut self, value: u16) -> Self {
357 self.port = value;
358 self
359 }
360 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
361 let node_id;
362 let host;
363 let port;
364 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
365 node_id = read_i32(buf)?;
366 host = read_compact_string(buf)?;
367 port = read_u16(buf)?;
368 let tagged_fields = read_tagged_fields(buf)?;
369 for field in &tagged_fields {
370 match field.tag {
371 _ => {
372 _unknown_tagged_fields.push(field.clone());
373 },
374 }
375 }
376 Ok(Self {
377 node_id,
378 host,
379 port,
380 _unknown_tagged_fields,
381 })
382 }
383 pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
384 write_i32(buf, self.node_id);
385 write_compact_string(buf, &self.host)?;
386 write_u16(buf, self.port);
387 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
388 all_tags.sort_by_key(|f| f.tag);
389 write_tagged_fields(buf, &all_tags)?;
390 Ok(())
391 }
392 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
393 let mut len: usize = 0;
394 len += 4;
395 len += compact_string_len(&self.host)?;
396 len += 2;
397 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
398 all_tags.sort_by_key(|f| f.tag);
399 len += tagged_fields_len(&all_tags)?;
400 Ok(len)
401 }
402}