kacrab_protocol/generated/
end_quorum_epoch_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 EndQuorumEpochResponseData {
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 EndQuorumEpochResponseData {
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 EndQuorumEpochResponseData {
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 > 1 {
50 return Err(UnsupportedVersion::new(54, 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 if version >= 1 {
58 topics = {
59 let len = read_compact_array_length(buf)?;
60 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
61 for _ in 0..len {
62 arr.push(TopicData::read(buf, version)?);
63 }
64 arr
65 };
66 } else {
67 topics = {
68 let len = read_array_length(buf)?;
69 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
70 for _ in 0..len {
71 arr.push(TopicData::read(buf, version)?);
72 }
73 arr
74 };
75 }
76 if version >= 1 {
77 let tagged_fields = read_tagged_fields(buf)?;
78 for field in &tagged_fields {
79 match field.tag {
80 0 => {
81 let mut tag_buf = field.data.clone();
82 node_endpoints = {
83 let len = read_compact_array_length(&mut tag_buf)?;
84 let mut arr =
85 Vec::with_capacity(array_read_capacity(len, (&mut tag_buf).len()));
86 for _ in 0..len {
87 arr.push(NodeEndpoint::read(&mut tag_buf, version)?);
88 }
89 arr
90 };
91 },
92 _ => {
93 _unknown_tagged_fields.push(field.clone());
94 },
95 }
96 }
97 }
98 Ok(Self {
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(54, version).into());
108 }
109 write_i16(buf, self.error_code);
110 if version >= 1 {
111 write_compact_array_length(buf, self.topics.len() as i32);
112 for el in &self.topics {
113 el.write(buf, version)?;
114 }
115 } else {
116 write_array_length(buf, self.topics.len() as i32);
117 for el in &self.topics {
118 el.write(buf, version)?;
119 }
120 }
121 if version >= 1 {
122 let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
123 if !self.node_endpoints.is_empty() {
124 let mut tag_buf = BytesMut::new();
125 write_compact_array_length(&mut tag_buf, self.node_endpoints.len() as i32);
126 for el in &self.node_endpoints {
127 el.write(&mut tag_buf, version)?;
128 }
129 known_tagged_fields.push(RawTaggedField {
130 tag: 0,
131 data: tag_buf.freeze(),
132 });
133 }
134 let mut all_tags = known_tagged_fields;
135 all_tags.extend(self._unknown_tagged_fields.iter().cloned());
136 all_tags.sort_by_key(|f| f.tag);
137 write_tagged_fields(buf, &all_tags)?;
138 }
139 Ok(())
140 }
141 pub fn encoded_len(&self, version: i16) -> Result<usize> {
142 if version < 0 || version > 1 {
143 return Err(UnsupportedVersion::new(54, version).into());
144 }
145 let mut len: usize = 0;
146 len += 2;
147 if version >= 1 {
148 len += compact_array_length_len(self.topics.len() as i32);
149 for el in &self.topics {
150 len += el.encoded_len(version)?;
151 }
152 } else {
153 len += array_length_len();
154 for el in &self.topics {
155 len += el.encoded_len(version)?;
156 }
157 }
158 if version >= 1 {
159 let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
160 if !self.node_endpoints.is_empty() {
161 let mut tag_buf = BytesMut::new();
162 write_compact_array_length(&mut tag_buf, self.node_endpoints.len() as i32);
163 for el in &self.node_endpoints {
164 el.write(&mut tag_buf, version)?;
165 }
166 known_tagged_fields.push(RawTaggedField {
167 tag: 0,
168 data: tag_buf.freeze(),
169 });
170 }
171 let mut all_tags = known_tagged_fields;
172 all_tags.extend(self._unknown_tagged_fields.iter().cloned());
173 all_tags.sort_by_key(|f| f.tag);
174 len += tagged_fields_len(&all_tags)?;
175 }
176 Ok(len)
177 }
178}
179#[derive(Debug, Clone, PartialEq)]
180pub struct TopicData {
181 pub topic_name: KafkaString,
183 pub partitions: Vec<PartitionData>,
185 pub _unknown_tagged_fields: Vec<RawTaggedField>,
186}
187impl Default for TopicData {
188 fn default() -> Self {
189 Self {
190 topic_name: KafkaString::default(),
191 partitions: Vec::new(),
192 _unknown_tagged_fields: Vec::new(),
193 }
194 }
195}
196impl TopicData {
197 pub fn with_topic_name(mut self, value: KafkaString) -> Self {
198 self.topic_name = value;
199 self
200 }
201 pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
202 self.partitions = value;
203 self
204 }
205 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
206 let topic_name;
207 let partitions;
208 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
209 if version >= 1 {
210 topic_name = read_compact_string(buf)?;
211 } else {
212 topic_name = read_string(buf)?;
213 }
214 if version >= 1 {
215 partitions = {
216 let len = read_compact_array_length(buf)?;
217 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
218 for _ in 0..len {
219 arr.push(PartitionData::read(buf, version)?);
220 }
221 arr
222 };
223 } else {
224 partitions = {
225 let len = read_array_length(buf)?;
226 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
227 for _ in 0..len {
228 arr.push(PartitionData::read(buf, version)?);
229 }
230 arr
231 };
232 }
233 if version >= 1 {
234 let tagged_fields = read_tagged_fields(buf)?;
235 for field in &tagged_fields {
236 match field.tag {
237 _ => {
238 _unknown_tagged_fields.push(field.clone());
239 },
240 }
241 }
242 }
243 Ok(Self {
244 topic_name,
245 partitions,
246 _unknown_tagged_fields,
247 })
248 }
249 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
250 if version >= 1 {
251 write_compact_string(buf, &self.topic_name)?;
252 } else {
253 write_string(buf, &self.topic_name)?;
254 }
255 if version >= 1 {
256 write_compact_array_length(buf, self.partitions.len() as i32);
257 for el in &self.partitions {
258 el.write(buf, version)?;
259 }
260 } else {
261 write_array_length(buf, self.partitions.len() as i32);
262 for el in &self.partitions {
263 el.write(buf, version)?;
264 }
265 }
266 if version >= 1 {
267 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
268 all_tags.sort_by_key(|f| f.tag);
269 write_tagged_fields(buf, &all_tags)?;
270 }
271 Ok(())
272 }
273 pub fn encoded_len(&self, version: i16) -> Result<usize> {
274 let mut len: usize = 0;
275 if version >= 1 {
276 len += compact_string_len(&self.topic_name)?;
277 } else {
278 len += string_len(&self.topic_name)?;
279 }
280 if version >= 1 {
281 len += compact_array_length_len(self.partitions.len() as i32);
282 for el in &self.partitions {
283 len += el.encoded_len(version)?;
284 }
285 } else {
286 len += array_length_len();
287 for el in &self.partitions {
288 len += el.encoded_len(version)?;
289 }
290 }
291 if version >= 1 {
292 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
293 all_tags.sort_by_key(|f| f.tag);
294 len += tagged_fields_len(&all_tags)?;
295 }
296 Ok(len)
297 }
298}
299#[derive(Debug, Clone, PartialEq)]
300pub struct PartitionData {
301 pub partition_index: i32,
303 pub error_code: i16,
305 pub leader_id: i32,
307 pub leader_epoch: i32,
309 pub _unknown_tagged_fields: Vec<RawTaggedField>,
310}
311impl Default for PartitionData {
312 fn default() -> Self {
313 Self {
314 partition_index: 0_i32,
315 error_code: 0_i16,
316 leader_id: 0_i32,
317 leader_epoch: 0_i32,
318 _unknown_tagged_fields: Vec::new(),
319 }
320 }
321}
322impl PartitionData {
323 pub fn with_partition_index(mut self, value: i32) -> Self {
324 self.partition_index = value;
325 self
326 }
327 pub fn with_error_code(mut self, value: i16) -> Self {
328 self.error_code = value;
329 self
330 }
331 pub fn with_leader_id(mut self, value: i32) -> Self {
332 self.leader_id = value;
333 self
334 }
335 pub fn with_leader_epoch(mut self, value: i32) -> Self {
336 self.leader_epoch = value;
337 self
338 }
339 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
340 let partition_index;
341 let error_code;
342 let leader_id;
343 let leader_epoch;
344 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
345 partition_index = read_i32(buf)?;
346 error_code = read_i16(buf)?;
347 leader_id = read_i32(buf)?;
348 leader_epoch = read_i32(buf)?;
349 if version >= 1 {
350 let tagged_fields = read_tagged_fields(buf)?;
351 for field in &tagged_fields {
352 match field.tag {
353 _ => {
354 _unknown_tagged_fields.push(field.clone());
355 },
356 }
357 }
358 }
359 Ok(Self {
360 partition_index,
361 error_code,
362 leader_id,
363 leader_epoch,
364 _unknown_tagged_fields,
365 })
366 }
367 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
368 write_i32(buf, self.partition_index);
369 write_i16(buf, self.error_code);
370 write_i32(buf, self.leader_id);
371 write_i32(buf, self.leader_epoch);
372 if version >= 1 {
373 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
374 all_tags.sort_by_key(|f| f.tag);
375 write_tagged_fields(buf, &all_tags)?;
376 }
377 Ok(())
378 }
379 pub fn encoded_len(&self, version: i16) -> Result<usize> {
380 let mut len: usize = 0;
381 len += 4;
382 len += 2;
383 len += 4;
384 len += 4;
385 if version >= 1 {
386 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
387 all_tags.sort_by_key(|f| f.tag);
388 len += tagged_fields_len(&all_tags)?;
389 }
390 Ok(len)
391 }
392}
393#[derive(Debug, Clone, PartialEq)]
394pub struct NodeEndpoint {
395 pub node_id: i32,
397 pub host: KafkaString,
399 pub port: u16,
401 pub _unknown_tagged_fields: Vec<RawTaggedField>,
402}
403impl Default for NodeEndpoint {
404 fn default() -> Self {
405 Self {
406 node_id: 0_i32,
407 host: KafkaString::default(),
408 port: 0_u16,
409 _unknown_tagged_fields: Vec::new(),
410 }
411 }
412}
413impl NodeEndpoint {
414 pub fn with_node_id(mut self, value: i32) -> Self {
415 self.node_id = value;
416 self
417 }
418 pub fn with_host(mut self, value: KafkaString) -> Self {
419 self.host = value;
420 self
421 }
422 pub fn with_port(mut self, value: u16) -> Self {
423 self.port = value;
424 self
425 }
426 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
427 let node_id;
428 let host;
429 let port;
430 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
431 node_id = read_i32(buf)?;
432 host = read_compact_string(buf)?;
433 port = read_u16(buf)?;
434 let tagged_fields = read_tagged_fields(buf)?;
435 for field in &tagged_fields {
436 match field.tag {
437 _ => {
438 _unknown_tagged_fields.push(field.clone());
439 },
440 }
441 }
442 Ok(Self {
443 node_id,
444 host,
445 port,
446 _unknown_tagged_fields,
447 })
448 }
449 pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
450 write_i32(buf, self.node_id);
451 write_compact_string(buf, &self.host)?;
452 write_u16(buf, self.port);
453 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
454 all_tags.sort_by_key(|f| f.tag);
455 write_tagged_fields(buf, &all_tags)?;
456 Ok(())
457 }
458 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
459 let mut len: usize = 0;
460 len += 4;
461 len += compact_string_len(&self.host)?;
462 len += 2;
463 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
464 all_tags.sort_by_key(|f| f.tag);
465 len += tagged_fields_len(&all_tags)?;
466 Ok(len)
467 }
468}