kacrab_protocol/generated/
create_partitions_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 CreatePartitionsRequestData {
17 pub topics: Vec<CreatePartitionsTopic>,
19 pub timeout_ms: i32,
21 pub validate_only: bool,
23 pub _unknown_tagged_fields: Vec<RawTaggedField>,
24}
25impl Default for CreatePartitionsRequestData {
26 fn default() -> Self {
27 Self {
28 topics: Vec::new(),
29 timeout_ms: 0_i32,
30 validate_only: false,
31 _unknown_tagged_fields: Vec::new(),
32 }
33 }
34}
35impl CreatePartitionsRequestData {
36 pub fn with_topics(mut self, value: Vec<CreatePartitionsTopic>) -> Self {
37 self.topics = value;
38 self
39 }
40 pub fn with_timeout_ms(mut self, value: i32) -> Self {
41 self.timeout_ms = value;
42 self
43 }
44 pub fn with_validate_only(mut self, value: bool) -> Self {
45 self.validate_only = value;
46 self
47 }
48 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
49 if version < 0 || version > 3 {
50 return Err(UnsupportedVersion::new(37, version).into());
51 }
52 let topics;
53 let timeout_ms;
54 let validate_only;
55 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
56 if version >= 2 {
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(CreatePartitionsTopic::read(buf, version)?);
62 }
63 arr
64 };
65 } else {
66 topics = {
67 let len = read_array_length(buf)?;
68 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
69 for _ in 0..len {
70 arr.push(CreatePartitionsTopic::read(buf, version)?);
71 }
72 arr
73 };
74 }
75 timeout_ms = read_i32(buf)?;
76 validate_only = read_bool(buf)?;
77 if version >= 2 {
78 let tagged_fields = read_tagged_fields(buf)?;
79 for field in &tagged_fields {
80 match field.tag {
81 _ => {
82 _unknown_tagged_fields.push(field.clone());
83 },
84 }
85 }
86 }
87 Ok(Self {
88 topics,
89 timeout_ms,
90 validate_only,
91 _unknown_tagged_fields,
92 })
93 }
94 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
95 if version < 0 || version > 3 {
96 return Err(UnsupportedVersion::new(37, version).into());
97 }
98 if version >= 2 {
99 write_compact_array_length(buf, self.topics.len() as i32);
100 for el in &self.topics {
101 el.write(buf, version)?;
102 }
103 } else {
104 write_array_length(buf, self.topics.len() as i32);
105 for el in &self.topics {
106 el.write(buf, version)?;
107 }
108 }
109 write_i32(buf, self.timeout_ms);
110 write_bool(buf, self.validate_only);
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 < 0 || version > 3 {
120 return Err(UnsupportedVersion::new(37, version).into());
121 }
122 let mut len: usize = 0;
123 if version >= 2 {
124 len += compact_array_length_len(self.topics.len() as i32);
125 for el in &self.topics {
126 len += el.encoded_len(version)?;
127 }
128 } else {
129 len += array_length_len();
130 for el in &self.topics {
131 len += el.encoded_len(version)?;
132 }
133 }
134 len += 4;
135 len += 1;
136 if version >= 2 {
137 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
138 all_tags.sort_by_key(|f| f.tag);
139 len += tagged_fields_len(&all_tags)?;
140 }
141 Ok(len)
142 }
143}
144#[derive(Debug, Clone, PartialEq)]
145pub struct CreatePartitionsTopic {
146 pub name: KafkaString,
148 pub count: i32,
150 pub assignments: Option<Vec<CreatePartitionsAssignment>>,
152 pub _unknown_tagged_fields: Vec<RawTaggedField>,
153}
154impl Default for CreatePartitionsTopic {
155 fn default() -> Self {
156 Self {
157 name: KafkaString::default(),
158 count: 0_i32,
159 assignments: None,
160 _unknown_tagged_fields: Vec::new(),
161 }
162 }
163}
164impl CreatePartitionsTopic {
165 pub fn with_name(mut self, value: KafkaString) -> Self {
166 self.name = value;
167 self
168 }
169 pub fn with_count(mut self, value: i32) -> Self {
170 self.count = value;
171 self
172 }
173 pub fn with_assignments(mut self, value: Option<Vec<CreatePartitionsAssignment>>) -> Self {
174 self.assignments = value;
175 self
176 }
177 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
178 let name;
179 let count;
180 let assignments;
181 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
182 if version >= 2 {
183 name = read_compact_string(buf)?;
184 } else {
185 name = read_string(buf)?;
186 }
187 count = read_i32(buf)?;
188 if version >= 2 {
189 assignments = {
190 let len = read_compact_array_length(buf)?;
191 if len < 0 {
192 None
193 } else {
194 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
195 for _ in 0..len {
196 arr.push(CreatePartitionsAssignment::read(buf, version)?);
197 }
198 Some(arr)
199 }
200 };
201 } else {
202 assignments = {
203 let len = read_array_length(buf)?;
204 if len < 0 {
205 None
206 } else {
207 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
208 for _ in 0..len {
209 arr.push(CreatePartitionsAssignment::read(buf, version)?);
210 }
211 Some(arr)
212 }
213 };
214 }
215 if version >= 2 {
216 let tagged_fields = read_tagged_fields(buf)?;
217 for field in &tagged_fields {
218 match field.tag {
219 _ => {
220 _unknown_tagged_fields.push(field.clone());
221 },
222 }
223 }
224 }
225 Ok(Self {
226 name,
227 count,
228 assignments,
229 _unknown_tagged_fields,
230 })
231 }
232 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
233 if version >= 2 {
234 write_compact_string(buf, &self.name)?;
235 } else {
236 write_string(buf, &self.name)?;
237 }
238 write_i32(buf, self.count);
239 if version >= 2 {
240 match &self.assignments {
241 None => {
242 write_compact_array_length(buf, -1);
243 },
244 Some(arr) => {
245 write_compact_array_length(buf, arr.len() as i32);
246 for el in arr {
247 el.write(buf, version)?;
248 }
249 },
250 }
251 } else {
252 match &self.assignments {
253 None => {
254 write_array_length(buf, -1);
255 },
256 Some(arr) => {
257 write_array_length(buf, arr.len() as i32);
258 for el in arr {
259 el.write(buf, version)?;
260 }
261 },
262 }
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 write_tagged_fields(buf, &all_tags)?;
268 }
269 Ok(())
270 }
271 pub fn encoded_len(&self, version: i16) -> Result<usize> {
272 let mut len: usize = 0;
273 if version >= 2 {
274 len += compact_string_len(&self.name)?;
275 } else {
276 len += string_len(&self.name)?;
277 }
278 len += 4;
279 if version >= 2 {
280 match &self.assignments {
281 None => {
282 len += compact_array_length_len(-1);
283 },
284 Some(arr) => {
285 len += compact_array_length_len(arr.len() as i32);
286 for el in arr {
287 len += el.encoded_len(version)?;
288 }
289 },
290 }
291 } else {
292 match &self.assignments {
293 None => {
294 len += array_length_len();
295 },
296 Some(arr) => {
297 len += array_length_len();
298 for el in arr {
299 len += el.encoded_len(version)?;
300 }
301 },
302 }
303 }
304 if version >= 2 {
305 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
306 all_tags.sort_by_key(|f| f.tag);
307 len += tagged_fields_len(&all_tags)?;
308 }
309 Ok(len)
310 }
311}
312#[derive(Debug, Clone, PartialEq)]
313pub struct CreatePartitionsAssignment {
314 pub broker_ids: Vec<i32>,
316 pub _unknown_tagged_fields: Vec<RawTaggedField>,
317}
318impl Default for CreatePartitionsAssignment {
319 fn default() -> Self {
320 Self {
321 broker_ids: Vec::new(),
322 _unknown_tagged_fields: Vec::new(),
323 }
324 }
325}
326impl CreatePartitionsAssignment {
327 pub fn with_broker_ids(mut self, value: Vec<i32>) -> Self {
328 self.broker_ids = value;
329 self
330 }
331 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
332 let broker_ids;
333 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
334 if version >= 2 {
335 broker_ids = {
336 let len = read_compact_array_length(buf)?;
337 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
338 for _ in 0..len {
339 arr.push(read_i32(buf)?);
340 }
341 arr
342 };
343 } else {
344 broker_ids = {
345 let len = read_array_length(buf)?;
346 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
347 for _ in 0..len {
348 arr.push(read_i32(buf)?);
349 }
350 arr
351 };
352 }
353 if version >= 2 {
354 let tagged_fields = read_tagged_fields(buf)?;
355 for field in &tagged_fields {
356 match field.tag {
357 _ => {
358 _unknown_tagged_fields.push(field.clone());
359 },
360 }
361 }
362 }
363 Ok(Self {
364 broker_ids,
365 _unknown_tagged_fields,
366 })
367 }
368 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
369 if version >= 2 {
370 write_compact_array_length(buf, self.broker_ids.len() as i32);
371 for el in &self.broker_ids {
372 write_i32(buf, *el);
373 }
374 } else {
375 write_array_length(buf, self.broker_ids.len() as i32);
376 for el in &self.broker_ids {
377 write_i32(buf, *el);
378 }
379 }
380 if version >= 2 {
381 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
382 all_tags.sort_by_key(|f| f.tag);
383 write_tagged_fields(buf, &all_tags)?;
384 }
385 Ok(())
386 }
387 pub fn encoded_len(&self, version: i16) -> Result<usize> {
388 let mut len: usize = 0;
389 if version >= 2 {
390 len += compact_array_length_len(self.broker_ids.len() as i32);
391 len += self.broker_ids.len() * 4usize;
392 } else {
393 len += array_length_len();
394 len += self.broker_ids.len() * 4usize;
395 }
396 if version >= 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 }
401 Ok(len)
402 }
403}