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