Skip to main content

kacrab_protocol/generated/
metadata_response.rs

1//! Generated from MetadataResponse.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 MetadataResponseData {
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    /// A list of brokers present in the cluster.
21    pub brokers: Vec<MetadataResponseBroker>,
22    /// The cluster ID that responding broker belongs to.
23    pub cluster_id: Option<KafkaString>,
24    /// The ID of the controller broker.
25    pub controller_id: i32,
26    /// Each topic in the response.
27    pub topics: Vec<MetadataResponseTopic>,
28    /// 32-bit bitfield to represent authorized operations for this cluster.
29    pub cluster_authorized_operations: i32,
30    /// The top-level error code, or 0 if there was no error.
31    pub error_code: i16,
32    pub _unknown_tagged_fields: Vec<RawTaggedField>,
33}
34impl Default for MetadataResponseData {
35    fn default() -> Self {
36        Self {
37            throttle_time_ms: 0_i32,
38            brokers: Vec::new(),
39            cluster_id: None,
40            controller_id: -1i32,
41            topics: Vec::new(),
42            cluster_authorized_operations: i32::MIN,
43            error_code: 0_i16,
44            _unknown_tagged_fields: Vec::new(),
45        }
46    }
47}
48impl MetadataResponseData {
49    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
50        self.throttle_time_ms = value;
51        self
52    }
53    pub fn with_brokers(mut self, value: Vec<MetadataResponseBroker>) -> Self {
54        self.brokers = value;
55        self
56    }
57    pub fn with_cluster_id(mut self, value: Option<KafkaString>) -> Self {
58        self.cluster_id = value;
59        self
60    }
61    pub fn with_controller_id(mut self, value: i32) -> Self {
62        self.controller_id = value;
63        self
64    }
65    pub fn with_topics(mut self, value: Vec<MetadataResponseTopic>) -> Self {
66        self.topics = value;
67        self
68    }
69    pub fn with_cluster_authorized_operations(mut self, value: i32) -> Self {
70        self.cluster_authorized_operations = value;
71        self
72    }
73    pub fn with_error_code(mut self, value: i16) -> Self {
74        self.error_code = value;
75        self
76    }
77    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
78        if version < 0 || version > 13 {
79            return Err(UnsupportedVersion::new(3, version).into());
80        }
81        let mut throttle_time_ms = 0_i32;
82        let brokers;
83        let mut cluster_id = None;
84        let mut controller_id = -1i32;
85        let topics;
86        let mut cluster_authorized_operations = i32::MIN;
87        let mut error_code = 0_i16;
88        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
89        if version >= 3 {
90            throttle_time_ms = read_i32(buf)?;
91        }
92        if version >= 9 {
93            brokers = {
94                let len = read_compact_array_length(buf)?;
95                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
96                for _ in 0..len {
97                    arr.push(MetadataResponseBroker::read(buf, version)?);
98                }
99                arr
100            };
101        } else {
102            brokers = {
103                let len = read_array_length(buf)?;
104                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
105                for _ in 0..len {
106                    arr.push(MetadataResponseBroker::read(buf, version)?);
107                }
108                arr
109            };
110        }
111        if version >= 2 {
112            if version >= 9 {
113                cluster_id = read_compact_nullable_string(buf)?;
114            } else {
115                cluster_id = read_nullable_string(buf)?;
116            }
117        }
118        if version >= 1 {
119            controller_id = read_i32(buf)?;
120        }
121        if version >= 9 {
122            topics = {
123                let len = read_compact_array_length(buf)?;
124                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
125                for _ in 0..len {
126                    arr.push(MetadataResponseTopic::read(buf, version)?);
127                }
128                arr
129            };
130        } else {
131            topics = {
132                let len = read_array_length(buf)?;
133                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
134                for _ in 0..len {
135                    arr.push(MetadataResponseTopic::read(buf, version)?);
136                }
137                arr
138            };
139        }
140        if version >= 8 && version <= 10 {
141            cluster_authorized_operations = read_i32(buf)?;
142        }
143        if version >= 13 {
144            error_code = read_i16(buf)?;
145        }
146        if version >= 9 {
147            let tagged_fields = read_tagged_fields(buf)?;
148            for field in &tagged_fields {
149                match field.tag {
150                    _ => {
151                        _unknown_tagged_fields.push(field.clone());
152                    },
153                }
154            }
155        }
156        Ok(Self {
157            throttle_time_ms,
158            brokers,
159            cluster_id,
160            controller_id,
161            topics,
162            cluster_authorized_operations,
163            error_code,
164            _unknown_tagged_fields,
165        })
166    }
167    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
168        if version < 0 || version > 13 {
169            return Err(UnsupportedVersion::new(3, version).into());
170        }
171        if version >= 3 {
172            write_i32(buf, self.throttle_time_ms);
173        } else if self.throttle_time_ms != 0_i32 {
174            return Err(UnsupportedFieldVersion::new(3, "throttle_time_ms", version).into());
175        }
176        if version >= 9 {
177            write_compact_array_length(buf, self.brokers.len() as i32);
178            for el in &self.brokers {
179                el.write(buf, version)?;
180            }
181        } else {
182            write_array_length(buf, self.brokers.len() as i32);
183            for el in &self.brokers {
184                el.write(buf, version)?;
185            }
186        }
187        if version >= 2 {
188            if version >= 9 {
189                write_compact_nullable_string(buf, self.cluster_id.as_ref())?;
190            } else {
191                write_nullable_string(buf, self.cluster_id.as_ref())?;
192            }
193        } else if self.cluster_id != None {
194            return Err(UnsupportedFieldVersion::new(3, "cluster_id", version).into());
195        }
196        if version >= 1 {
197            write_i32(buf, self.controller_id);
198        } else if self.controller_id != -1i32 {
199            return Err(UnsupportedFieldVersion::new(3, "controller_id", version).into());
200        }
201        if version >= 9 {
202            write_compact_array_length(buf, self.topics.len() as i32);
203            for el in &self.topics {
204                el.write(buf, version)?;
205            }
206        } else {
207            write_array_length(buf, self.topics.len() as i32);
208            for el in &self.topics {
209                el.write(buf, version)?;
210            }
211        }
212        if version >= 8 && version <= 10 {
213            write_i32(buf, self.cluster_authorized_operations);
214        } else if self.cluster_authorized_operations != i32::MIN {
215            return Err(
216                UnsupportedFieldVersion::new(3, "cluster_authorized_operations", version).into(),
217            );
218        }
219        if version >= 13 {
220            write_i16(buf, self.error_code);
221        } else if self.error_code != 0_i16 {
222            return Err(UnsupportedFieldVersion::new(3, "error_code", version).into());
223        }
224        if version >= 9 {
225            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
226            all_tags.sort_by_key(|f| f.tag);
227            write_tagged_fields(buf, &all_tags)?;
228        }
229        Ok(())
230    }
231    pub fn encoded_len(&self, version: i16) -> Result<usize> {
232        if version < 0 || version > 13 {
233            return Err(UnsupportedVersion::new(3, version).into());
234        }
235        let mut len: usize = 0;
236        if version >= 3 {
237            len += 4;
238        } else if self.throttle_time_ms != 0_i32 {
239            return Err(UnsupportedFieldVersion::new(3, "throttle_time_ms", version).into());
240        }
241        if version >= 9 {
242            len += compact_array_length_len(self.brokers.len() as i32);
243            for el in &self.brokers {
244                len += el.encoded_len(version)?;
245            }
246        } else {
247            len += array_length_len();
248            for el in &self.brokers {
249                len += el.encoded_len(version)?;
250            }
251        }
252        if version >= 2 {
253            if version >= 9 {
254                len += compact_nullable_string_len(self.cluster_id.as_ref())?;
255            } else {
256                len += nullable_string_len(self.cluster_id.as_ref())?;
257            }
258        } else if self.cluster_id != None {
259            return Err(UnsupportedFieldVersion::new(3, "cluster_id", version).into());
260        }
261        if version >= 1 {
262            len += 4;
263        } else if self.controller_id != -1i32 {
264            return Err(UnsupportedFieldVersion::new(3, "controller_id", version).into());
265        }
266        if version >= 9 {
267            len += compact_array_length_len(self.topics.len() as i32);
268            for el in &self.topics {
269                len += el.encoded_len(version)?;
270            }
271        } else {
272            len += array_length_len();
273            for el in &self.topics {
274                len += el.encoded_len(version)?;
275            }
276        }
277        if version >= 8 && version <= 10 {
278            len += 4;
279        } else if self.cluster_authorized_operations != i32::MIN {
280            return Err(
281                UnsupportedFieldVersion::new(3, "cluster_authorized_operations", version).into(),
282            );
283        }
284        if version >= 13 {
285            len += 2;
286        } else if self.error_code != 0_i16 {
287            return Err(UnsupportedFieldVersion::new(3, "error_code", version).into());
288        }
289        if version >= 9 {
290            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
291            all_tags.sort_by_key(|f| f.tag);
292            len += tagged_fields_len(&all_tags)?;
293        }
294        Ok(len)
295    }
296}
297#[derive(Debug, Clone, PartialEq)]
298pub struct MetadataResponseBroker {
299    /// The broker ID.
300    pub node_id: i32,
301    /// The broker hostname.
302    pub host: KafkaString,
303    /// The broker port.
304    pub port: i32,
305    /// The rack of the broker, or null if it has not been assigned to a rack.
306    pub rack: Option<KafkaString>,
307    pub _unknown_tagged_fields: Vec<RawTaggedField>,
308}
309impl Default for MetadataResponseBroker {
310    fn default() -> Self {
311        Self {
312            node_id: 0_i32,
313            host: KafkaString::default(),
314            port: 0_i32,
315            rack: None,
316            _unknown_tagged_fields: Vec::new(),
317        }
318    }
319}
320impl MetadataResponseBroker {
321    pub fn with_node_id(mut self, value: i32) -> Self {
322        self.node_id = value;
323        self
324    }
325    pub fn with_host(mut self, value: KafkaString) -> Self {
326        self.host = value;
327        self
328    }
329    pub fn with_port(mut self, value: i32) -> Self {
330        self.port = value;
331        self
332    }
333    pub fn with_rack(mut self, value: Option<KafkaString>) -> Self {
334        self.rack = value;
335        self
336    }
337    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
338        let node_id;
339        let host;
340        let port;
341        let mut rack = None;
342        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
343        node_id = read_i32(buf)?;
344        if version >= 9 {
345            host = read_compact_string(buf)?;
346        } else {
347            host = read_string(buf)?;
348        }
349        port = read_i32(buf)?;
350        if version >= 1 {
351            if version >= 9 {
352                rack = read_compact_nullable_string(buf)?;
353            } else {
354                rack = read_nullable_string(buf)?;
355            }
356        }
357        if version >= 9 {
358            let tagged_fields = read_tagged_fields(buf)?;
359            for field in &tagged_fields {
360                match field.tag {
361                    _ => {
362                        _unknown_tagged_fields.push(field.clone());
363                    },
364                }
365            }
366        }
367        Ok(Self {
368            node_id,
369            host,
370            port,
371            rack,
372            _unknown_tagged_fields,
373        })
374    }
375    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
376        write_i32(buf, self.node_id);
377        if version >= 9 {
378            write_compact_string(buf, &self.host)?;
379        } else {
380            write_string(buf, &self.host)?;
381        }
382        write_i32(buf, self.port);
383        if version >= 1 {
384            if version >= 9 {
385                write_compact_nullable_string(buf, self.rack.as_ref())?;
386            } else {
387                write_nullable_string(buf, self.rack.as_ref())?;
388            }
389        } else if self.rack != None {
390            return Err(UnsupportedFieldVersion::new(3, "rack", version).into());
391        }
392        if version >= 9 {
393            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
394            all_tags.sort_by_key(|f| f.tag);
395            write_tagged_fields(buf, &all_tags)?;
396        }
397        Ok(())
398    }
399    pub fn encoded_len(&self, version: i16) -> Result<usize> {
400        let mut len: usize = 0;
401        len += 4;
402        if version >= 9 {
403            len += compact_string_len(&self.host)?;
404        } else {
405            len += string_len(&self.host)?;
406        }
407        len += 4;
408        if version >= 1 {
409            if version >= 9 {
410                len += compact_nullable_string_len(self.rack.as_ref())?;
411            } else {
412                len += nullable_string_len(self.rack.as_ref())?;
413            }
414        } else if self.rack != None {
415            return Err(UnsupportedFieldVersion::new(3, "rack", version).into());
416        }
417        if version >= 9 {
418            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
419            all_tags.sort_by_key(|f| f.tag);
420            len += tagged_fields_len(&all_tags)?;
421        }
422        Ok(len)
423    }
424}
425#[derive(Debug, Clone, PartialEq)]
426pub struct MetadataResponseTopic {
427    /// The topic error, or 0 if there was no error.
428    pub error_code: i16,
429    /// The topic name. Null for non-existing topics queried by ID. This is never null when
430    /// ErrorCode is zero. One of Name and TopicId is always populated.
431    pub name: Option<KafkaString>,
432    /// The topic id. Zero for non-existing topics queried by name. This is never zero when
433    /// ErrorCode is zero. One of Name and TopicId is always populated.
434    pub topic_id: KafkaUuid,
435    /// True if the topic is internal.
436    pub is_internal: bool,
437    /// Each partition in the topic.
438    pub partitions: Vec<MetadataResponsePartition>,
439    /// 32-bit bitfield to represent authorized operations for this topic.
440    pub topic_authorized_operations: i32,
441    pub _unknown_tagged_fields: Vec<RawTaggedField>,
442}
443impl Default for MetadataResponseTopic {
444    fn default() -> Self {
445        Self {
446            error_code: 0_i16,
447            name: None,
448            topic_id: KafkaUuid::ZERO,
449            is_internal: false,
450            partitions: Vec::new(),
451            topic_authorized_operations: i32::MIN,
452            _unknown_tagged_fields: Vec::new(),
453        }
454    }
455}
456impl MetadataResponseTopic {
457    pub fn with_error_code(mut self, value: i16) -> Self {
458        self.error_code = value;
459        self
460    }
461    pub fn with_name(mut self, value: Option<KafkaString>) -> Self {
462        self.name = value;
463        self
464    }
465    pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
466        self.topic_id = value;
467        self
468    }
469    pub fn with_is_internal(mut self, value: bool) -> Self {
470        self.is_internal = value;
471        self
472    }
473    pub fn with_partitions(mut self, value: Vec<MetadataResponsePartition>) -> Self {
474        self.partitions = value;
475        self
476    }
477    pub fn with_topic_authorized_operations(mut self, value: i32) -> Self {
478        self.topic_authorized_operations = value;
479        self
480    }
481    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
482        let error_code;
483        let name;
484        let mut topic_id = KafkaUuid::ZERO;
485        let mut is_internal = false;
486        let partitions;
487        let mut topic_authorized_operations = i32::MIN;
488        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
489        error_code = read_i16(buf)?;
490        if version >= 12 {
491            name = read_compact_nullable_string(buf)?;
492        } else {
493            if version >= 9 {
494                name = Some(read_compact_string(buf)?);
495            } else {
496                name = Some(read_string(buf)?);
497            }
498        }
499        if version >= 10 {
500            topic_id = read_uuid(buf)?;
501        }
502        if version >= 1 {
503            is_internal = read_bool(buf)?;
504        }
505        if version >= 9 {
506            partitions = {
507                let len = read_compact_array_length(buf)?;
508                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
509                for _ in 0..len {
510                    arr.push(MetadataResponsePartition::read(buf, version)?);
511                }
512                arr
513            };
514        } else {
515            partitions = {
516                let len = read_array_length(buf)?;
517                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
518                for _ in 0..len {
519                    arr.push(MetadataResponsePartition::read(buf, version)?);
520                }
521                arr
522            };
523        }
524        if version >= 8 {
525            topic_authorized_operations = read_i32(buf)?;
526        }
527        if version >= 9 {
528            let tagged_fields = read_tagged_fields(buf)?;
529            for field in &tagged_fields {
530                match field.tag {
531                    _ => {
532                        _unknown_tagged_fields.push(field.clone());
533                    },
534                }
535            }
536        }
537        Ok(Self {
538            error_code,
539            name,
540            topic_id,
541            is_internal,
542            partitions,
543            topic_authorized_operations,
544            _unknown_tagged_fields,
545        })
546    }
547    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
548        write_i16(buf, self.error_code);
549        if version >= 12 {
550            write_compact_nullable_string(buf, self.name.as_ref())?;
551        } else {
552            {
553                let _nn_default = KafkaString::default();
554                let _nn_val = self.name.as_ref().unwrap_or(&_nn_default);
555                if version >= 9 {
556                    write_compact_string(buf, _nn_val)?;
557                } else {
558                    write_string(buf, _nn_val)?;
559                }
560            }
561        }
562        if version >= 10 {
563            write_uuid(buf, &self.topic_id);
564        } else if self.topic_id != KafkaUuid::ZERO {
565            return Err(UnsupportedFieldVersion::new(3, "topic_id", version).into());
566        }
567        if version >= 1 {
568            write_bool(buf, self.is_internal);
569        } else if self.is_internal != false {
570            return Err(UnsupportedFieldVersion::new(3, "is_internal", version).into());
571        }
572        if version >= 9 {
573            write_compact_array_length(buf, self.partitions.len() as i32);
574            for el in &self.partitions {
575                el.write(buf, version)?;
576            }
577        } else {
578            write_array_length(buf, self.partitions.len() as i32);
579            for el in &self.partitions {
580                el.write(buf, version)?;
581            }
582        }
583        if version >= 8 {
584            write_i32(buf, self.topic_authorized_operations);
585        } else if self.topic_authorized_operations != i32::MIN {
586            return Err(
587                UnsupportedFieldVersion::new(3, "topic_authorized_operations", version).into(),
588            );
589        }
590        if version >= 9 {
591            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
592            all_tags.sort_by_key(|f| f.tag);
593            write_tagged_fields(buf, &all_tags)?;
594        }
595        Ok(())
596    }
597    pub fn encoded_len(&self, version: i16) -> Result<usize> {
598        let mut len: usize = 0;
599        len += 2;
600        if version >= 12 {
601            len += compact_nullable_string_len(self.name.as_ref())?;
602        } else {
603            let _nn_default = KafkaString::default();
604            let _nn_val = self.name.as_ref().unwrap_or(&_nn_default);
605            if version >= 9 {
606                len += compact_string_len(_nn_val)?;
607            } else {
608                len += string_len(_nn_val)?;
609            }
610        }
611        if version >= 10 {
612            len += 16;
613        } else if self.topic_id != KafkaUuid::ZERO {
614            return Err(UnsupportedFieldVersion::new(3, "topic_id", version).into());
615        }
616        if version >= 1 {
617            len += 1;
618        } else if self.is_internal != false {
619            return Err(UnsupportedFieldVersion::new(3, "is_internal", version).into());
620        }
621        if version >= 9 {
622            len += compact_array_length_len(self.partitions.len() as i32);
623            for el in &self.partitions {
624                len += el.encoded_len(version)?;
625            }
626        } else {
627            len += array_length_len();
628            for el in &self.partitions {
629                len += el.encoded_len(version)?;
630            }
631        }
632        if version >= 8 {
633            len += 4;
634        } else if self.topic_authorized_operations != i32::MIN {
635            return Err(
636                UnsupportedFieldVersion::new(3, "topic_authorized_operations", version).into(),
637            );
638        }
639        if version >= 9 {
640            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
641            all_tags.sort_by_key(|f| f.tag);
642            len += tagged_fields_len(&all_tags)?;
643        }
644        Ok(len)
645    }
646}
647#[derive(Debug, Clone, PartialEq)]
648pub struct MetadataResponsePartition {
649    /// The partition error, or 0 if there was no error.
650    pub error_code: i16,
651    /// The partition index.
652    pub partition_index: i32,
653    /// The ID of the leader broker.
654    pub leader_id: i32,
655    /// The leader epoch of this partition.
656    pub leader_epoch: i32,
657    /// The set of all nodes that host this partition.
658    pub replica_nodes: Vec<i32>,
659    /// The set of nodes that are in sync with the leader for this partition.
660    pub isr_nodes: Vec<i32>,
661    /// The set of offline replicas of this partition.
662    pub offline_replicas: Vec<i32>,
663    pub _unknown_tagged_fields: Vec<RawTaggedField>,
664}
665impl Default for MetadataResponsePartition {
666    fn default() -> Self {
667        Self {
668            error_code: 0_i16,
669            partition_index: 0_i32,
670            leader_id: 0_i32,
671            leader_epoch: -1i32,
672            replica_nodes: Vec::new(),
673            isr_nodes: Vec::new(),
674            offline_replicas: Vec::new(),
675            _unknown_tagged_fields: Vec::new(),
676        }
677    }
678}
679impl MetadataResponsePartition {
680    pub fn with_error_code(mut self, value: i16) -> Self {
681        self.error_code = value;
682        self
683    }
684    pub fn with_partition_index(mut self, value: i32) -> Self {
685        self.partition_index = value;
686        self
687    }
688    pub fn with_leader_id(mut self, value: i32) -> Self {
689        self.leader_id = value;
690        self
691    }
692    pub fn with_leader_epoch(mut self, value: i32) -> Self {
693        self.leader_epoch = value;
694        self
695    }
696    pub fn with_replica_nodes(mut self, value: Vec<i32>) -> Self {
697        self.replica_nodes = value;
698        self
699    }
700    pub fn with_isr_nodes(mut self, value: Vec<i32>) -> Self {
701        self.isr_nodes = value;
702        self
703    }
704    pub fn with_offline_replicas(mut self, value: Vec<i32>) -> Self {
705        self.offline_replicas = value;
706        self
707    }
708    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
709        let error_code;
710        let partition_index;
711        let leader_id;
712        let mut leader_epoch = -1i32;
713        let replica_nodes;
714        let isr_nodes;
715        let mut offline_replicas = Vec::new();
716        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
717        error_code = read_i16(buf)?;
718        partition_index = read_i32(buf)?;
719        leader_id = read_i32(buf)?;
720        if version >= 7 {
721            leader_epoch = read_i32(buf)?;
722        }
723        if version >= 9 {
724            replica_nodes = {
725                let len = read_compact_array_length(buf)?;
726                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
727                for _ in 0..len {
728                    arr.push(read_i32(buf)?);
729                }
730                arr
731            };
732        } else {
733            replica_nodes = {
734                let len = read_array_length(buf)?;
735                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
736                for _ in 0..len {
737                    arr.push(read_i32(buf)?);
738                }
739                arr
740            };
741        }
742        if version >= 9 {
743            isr_nodes = {
744                let len = read_compact_array_length(buf)?;
745                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
746                for _ in 0..len {
747                    arr.push(read_i32(buf)?);
748                }
749                arr
750            };
751        } else {
752            isr_nodes = {
753                let len = read_array_length(buf)?;
754                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
755                for _ in 0..len {
756                    arr.push(read_i32(buf)?);
757                }
758                arr
759            };
760        }
761        if version >= 5 {
762            if version >= 9 {
763                offline_replicas = {
764                    let len = read_compact_array_length(buf)?;
765                    let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
766                    for _ in 0..len {
767                        arr.push(read_i32(buf)?);
768                    }
769                    arr
770                };
771            } else {
772                offline_replicas = {
773                    let len = read_array_length(buf)?;
774                    let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
775                    for _ in 0..len {
776                        arr.push(read_i32(buf)?);
777                    }
778                    arr
779                };
780            }
781        }
782        if version >= 9 {
783            let tagged_fields = read_tagged_fields(buf)?;
784            for field in &tagged_fields {
785                match field.tag {
786                    _ => {
787                        _unknown_tagged_fields.push(field.clone());
788                    },
789                }
790            }
791        }
792        Ok(Self {
793            error_code,
794            partition_index,
795            leader_id,
796            leader_epoch,
797            replica_nodes,
798            isr_nodes,
799            offline_replicas,
800            _unknown_tagged_fields,
801        })
802    }
803    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
804        write_i16(buf, self.error_code);
805        write_i32(buf, self.partition_index);
806        write_i32(buf, self.leader_id);
807        if version >= 7 {
808            write_i32(buf, self.leader_epoch);
809        } else if self.leader_epoch != -1i32 {
810            return Err(UnsupportedFieldVersion::new(3, "leader_epoch", version).into());
811        }
812        if version >= 9 {
813            write_compact_array_length(buf, self.replica_nodes.len() as i32);
814            for el in &self.replica_nodes {
815                write_i32(buf, *el);
816            }
817        } else {
818            write_array_length(buf, self.replica_nodes.len() as i32);
819            for el in &self.replica_nodes {
820                write_i32(buf, *el);
821            }
822        }
823        if version >= 9 {
824            write_compact_array_length(buf, self.isr_nodes.len() as i32);
825            for el in &self.isr_nodes {
826                write_i32(buf, *el);
827            }
828        } else {
829            write_array_length(buf, self.isr_nodes.len() as i32);
830            for el in &self.isr_nodes {
831                write_i32(buf, *el);
832            }
833        }
834        if version >= 5 {
835            if version >= 9 {
836                write_compact_array_length(buf, self.offline_replicas.len() as i32);
837                for el in &self.offline_replicas {
838                    write_i32(buf, *el);
839                }
840            } else {
841                write_array_length(buf, self.offline_replicas.len() as i32);
842                for el in &self.offline_replicas {
843                    write_i32(buf, *el);
844                }
845            }
846        } else if self.offline_replicas != Vec::new() {
847            return Err(UnsupportedFieldVersion::new(3, "offline_replicas", version).into());
848        }
849        if version >= 9 {
850            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
851            all_tags.sort_by_key(|f| f.tag);
852            write_tagged_fields(buf, &all_tags)?;
853        }
854        Ok(())
855    }
856    pub fn encoded_len(&self, version: i16) -> Result<usize> {
857        let mut len: usize = 0;
858        len += 2;
859        len += 4;
860        len += 4;
861        if version >= 7 {
862            len += 4;
863        } else if self.leader_epoch != -1i32 {
864            return Err(UnsupportedFieldVersion::new(3, "leader_epoch", version).into());
865        }
866        if version >= 9 {
867            len += compact_array_length_len(self.replica_nodes.len() as i32);
868            len += self.replica_nodes.len() * 4usize;
869        } else {
870            len += array_length_len();
871            len += self.replica_nodes.len() * 4usize;
872        }
873        if version >= 9 {
874            len += compact_array_length_len(self.isr_nodes.len() as i32);
875            len += self.isr_nodes.len() * 4usize;
876        } else {
877            len += array_length_len();
878            len += self.isr_nodes.len() * 4usize;
879        }
880        if version >= 5 {
881            if version >= 9 {
882                len += compact_array_length_len(self.offline_replicas.len() as i32);
883                len += self.offline_replicas.len() * 4usize;
884            } else {
885                len += array_length_len();
886                len += self.offline_replicas.len() * 4usize;
887            }
888        } else if self.offline_replicas != Vec::new() {
889            return Err(UnsupportedFieldVersion::new(3, "offline_replicas", version).into());
890        }
891        if version >= 9 {
892            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
893            all_tags.sort_by_key(|f| f.tag);
894            len += tagged_fields_len(&all_tags)?;
895        }
896        Ok(len)
897    }
898}