Skip to main content

kacrab_protocol/generated/
describe_producers_request.rs

1//! Generated from DescribeProducersRequest.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 DescribeProducersRequestData {
17    /// The topics to list producers for.
18    pub topics: Vec<TopicRequest>,
19    pub _unknown_tagged_fields: Vec<RawTaggedField>,
20}
21impl Default for DescribeProducersRequestData {
22    fn default() -> Self {
23        Self {
24            topics: Vec::new(),
25            _unknown_tagged_fields: Vec::new(),
26        }
27    }
28}
29impl DescribeProducersRequestData {
30    pub fn with_topics(mut self, value: Vec<TopicRequest>) -> Self {
31        self.topics = value;
32        self
33    }
34    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
35        if version < 0 || version > 0 {
36            return Err(UnsupportedVersion::new(61, 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(TopicRequest::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 > 0 {
63            return Err(UnsupportedVersion::new(61, 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 > 0 {
76            return Err(UnsupportedVersion::new(61, 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 TopicRequest {
91    /// The topic name.
92    pub name: KafkaString,
93    /// The indexes of the partitions to list producers for.
94    pub partition_indexes: Vec<i32>,
95    pub _unknown_tagged_fields: Vec<RawTaggedField>,
96}
97impl Default for TopicRequest {
98    fn default() -> Self {
99        Self {
100            name: KafkaString::default(),
101            partition_indexes: Vec::new(),
102            _unknown_tagged_fields: Vec::new(),
103        }
104    }
105}
106impl TopicRequest {
107    pub fn with_name(mut self, value: KafkaString) -> Self {
108        self.name = value;
109        self
110    }
111    pub fn with_partition_indexes(mut self, value: Vec<i32>) -> Self {
112        self.partition_indexes = value;
113        self
114    }
115    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
116        let name;
117        let partition_indexes;
118        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
119        name = read_compact_string(buf)?;
120        partition_indexes = {
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(read_i32(buf)?);
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            name,
138            partition_indexes,
139            _unknown_tagged_fields,
140        })
141    }
142    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
143        write_compact_string(buf, &self.name)?;
144        write_compact_array_length(buf, self.partition_indexes.len() as i32);
145        for el in &self.partition_indexes {
146            write_i32(buf, *el);
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.name)?;
156        len += compact_array_length_len(self.partition_indexes.len() as i32);
157        len += self.partition_indexes.len() * 4usize;
158        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
159        all_tags.sort_by_key(|f| f.tag);
160        len += tagged_fields_len(&all_tags)?;
161        Ok(len)
162    }
163}