Skip to main content

kacrab_protocol/generated/
create_topics_request.rs

1//! Generated from CreateTopicsRequest.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 CreateTopicsRequestData {
17    /// The topics to create.
18    pub topics: Vec<CreatableTopic>,
19    /// How long to wait in milliseconds before timing out the request.
20    pub timeout_ms: i32,
21    /// If true, check that the topics can be created as specified, but don't create anything.
22    pub validate_only: bool,
23    pub _unknown_tagged_fields: Vec<RawTaggedField>,
24}
25impl Default for CreateTopicsRequestData {
26    fn default() -> Self {
27        Self {
28            topics: Vec::new(),
29            timeout_ms: 60000i32,
30            validate_only: false,
31            _unknown_tagged_fields: Vec::new(),
32        }
33    }
34}
35impl CreateTopicsRequestData {
36    pub fn with_topics(mut self, value: Vec<CreatableTopic>) -> 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 < 2 || version > 7 {
50            return Err(UnsupportedVersion::new(19, 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 >= 5 {
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(CreatableTopic::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(CreatableTopic::read(buf, version)?);
71                }
72                arr
73            };
74        }
75        timeout_ms = read_i32(buf)?;
76        validate_only = read_bool(buf)?;
77        if version >= 5 {
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 < 2 || version > 7 {
96            return Err(UnsupportedVersion::new(19, version).into());
97        }
98        if version >= 5 {
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 >= 5 {
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 < 2 || version > 7 {
120            return Err(UnsupportedVersion::new(19, version).into());
121        }
122        let mut len: usize = 0;
123        if version >= 5 {
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 >= 5 {
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 CreatableTopic {
146    /// The topic name.
147    pub name: KafkaString,
148    /// The number of partitions to create in the topic, or -1 if we are either specifying a manual
149    /// partition assignment or using the default partitions.
150    pub num_partitions: i32,
151    /// The number of replicas to create for each partition in the topic, or -1 if we are either
152    /// specifying a manual partition assignment or using the default replication factor.
153    pub replication_factor: i16,
154    /// The manual partition assignment, or the empty array if we are using automatic assignment.
155    pub assignments: Vec<CreatableReplicaAssignment>,
156    /// The custom topic configurations to set.
157    pub configs: Vec<CreatableTopicConfig>,
158    pub _unknown_tagged_fields: Vec<RawTaggedField>,
159}
160impl Default for CreatableTopic {
161    fn default() -> Self {
162        Self {
163            name: KafkaString::default(),
164            num_partitions: 0_i32,
165            replication_factor: 0_i16,
166            assignments: Vec::new(),
167            configs: Vec::new(),
168            _unknown_tagged_fields: Vec::new(),
169        }
170    }
171}
172impl CreatableTopic {
173    pub fn with_name(mut self, value: KafkaString) -> Self {
174        self.name = value;
175        self
176    }
177    pub fn with_num_partitions(mut self, value: i32) -> Self {
178        self.num_partitions = value;
179        self
180    }
181    pub fn with_replication_factor(mut self, value: i16) -> Self {
182        self.replication_factor = value;
183        self
184    }
185    pub fn with_assignments(mut self, value: Vec<CreatableReplicaAssignment>) -> Self {
186        self.assignments = value;
187        self
188    }
189    pub fn with_configs(mut self, value: Vec<CreatableTopicConfig>) -> Self {
190        self.configs = value;
191        self
192    }
193    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
194        let name;
195        let num_partitions;
196        let replication_factor;
197        let assignments;
198        let configs;
199        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
200        if version >= 5 {
201            name = read_compact_string(buf)?;
202        } else {
203            name = read_string(buf)?;
204        }
205        num_partitions = read_i32(buf)?;
206        replication_factor = read_i16(buf)?;
207        if version >= 5 {
208            assignments = {
209                let len = read_compact_array_length(buf)?;
210                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
211                for _ in 0..len {
212                    arr.push(CreatableReplicaAssignment::read(buf, version)?);
213                }
214                arr
215            };
216        } else {
217            assignments = {
218                let len = read_array_length(buf)?;
219                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
220                for _ in 0..len {
221                    arr.push(CreatableReplicaAssignment::read(buf, version)?);
222                }
223                arr
224            };
225        }
226        if version >= 5 {
227            configs = {
228                let len = read_compact_array_length(buf)?;
229                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
230                for _ in 0..len {
231                    arr.push(CreatableTopicConfig::read(buf, version)?);
232                }
233                arr
234            };
235        } else {
236            configs = {
237                let len = read_array_length(buf)?;
238                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
239                for _ in 0..len {
240                    arr.push(CreatableTopicConfig::read(buf, version)?);
241                }
242                arr
243            };
244        }
245        if version >= 5 {
246            let tagged_fields = read_tagged_fields(buf)?;
247            for field in &tagged_fields {
248                match field.tag {
249                    _ => {
250                        _unknown_tagged_fields.push(field.clone());
251                    },
252                }
253            }
254        }
255        Ok(Self {
256            name,
257            num_partitions,
258            replication_factor,
259            assignments,
260            configs,
261            _unknown_tagged_fields,
262        })
263    }
264    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
265        if version >= 5 {
266            write_compact_string(buf, &self.name)?;
267        } else {
268            write_string(buf, &self.name)?;
269        }
270        write_i32(buf, self.num_partitions);
271        write_i16(buf, self.replication_factor);
272        if version >= 5 {
273            write_compact_array_length(buf, self.assignments.len() as i32);
274            for el in &self.assignments {
275                el.write(buf, version)?;
276            }
277        } else {
278            write_array_length(buf, self.assignments.len() as i32);
279            for el in &self.assignments {
280                el.write(buf, version)?;
281            }
282        }
283        if version >= 5 {
284            write_compact_array_length(buf, self.configs.len() as i32);
285            for el in &self.configs {
286                el.write(buf, version)?;
287            }
288        } else {
289            write_array_length(buf, self.configs.len() as i32);
290            for el in &self.configs {
291                el.write(buf, version)?;
292            }
293        }
294        if version >= 5 {
295            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
296            all_tags.sort_by_key(|f| f.tag);
297            write_tagged_fields(buf, &all_tags)?;
298        }
299        Ok(())
300    }
301    pub fn encoded_len(&self, version: i16) -> Result<usize> {
302        let mut len: usize = 0;
303        if version >= 5 {
304            len += compact_string_len(&self.name)?;
305        } else {
306            len += string_len(&self.name)?;
307        }
308        len += 4;
309        len += 2;
310        if version >= 5 {
311            len += compact_array_length_len(self.assignments.len() as i32);
312            for el in &self.assignments {
313                len += el.encoded_len(version)?;
314            }
315        } else {
316            len += array_length_len();
317            for el in &self.assignments {
318                len += el.encoded_len(version)?;
319            }
320        }
321        if version >= 5 {
322            len += compact_array_length_len(self.configs.len() as i32);
323            for el in &self.configs {
324                len += el.encoded_len(version)?;
325            }
326        } else {
327            len += array_length_len();
328            for el in &self.configs {
329                len += el.encoded_len(version)?;
330            }
331        }
332        if version >= 5 {
333            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
334            all_tags.sort_by_key(|f| f.tag);
335            len += tagged_fields_len(&all_tags)?;
336        }
337        Ok(len)
338    }
339}
340#[derive(Debug, Clone, PartialEq)]
341pub struct CreatableReplicaAssignment {
342    /// The partition index.
343    pub partition_index: i32,
344    /// The brokers to place the partition on.
345    pub broker_ids: Vec<i32>,
346    pub _unknown_tagged_fields: Vec<RawTaggedField>,
347}
348impl Default for CreatableReplicaAssignment {
349    fn default() -> Self {
350        Self {
351            partition_index: 0_i32,
352            broker_ids: Vec::new(),
353            _unknown_tagged_fields: Vec::new(),
354        }
355    }
356}
357impl CreatableReplicaAssignment {
358    pub fn with_partition_index(mut self, value: i32) -> Self {
359        self.partition_index = value;
360        self
361    }
362    pub fn with_broker_ids(mut self, value: Vec<i32>) -> Self {
363        self.broker_ids = value;
364        self
365    }
366    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
367        let partition_index;
368        let broker_ids;
369        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
370        partition_index = read_i32(buf)?;
371        if version >= 5 {
372            broker_ids = {
373                let len = read_compact_array_length(buf)?;
374                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
375                for _ in 0..len {
376                    arr.push(read_i32(buf)?);
377                }
378                arr
379            };
380        } else {
381            broker_ids = {
382                let len = read_array_length(buf)?;
383                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
384                for _ in 0..len {
385                    arr.push(read_i32(buf)?);
386                }
387                arr
388            };
389        }
390        if version >= 5 {
391            let tagged_fields = read_tagged_fields(buf)?;
392            for field in &tagged_fields {
393                match field.tag {
394                    _ => {
395                        _unknown_tagged_fields.push(field.clone());
396                    },
397                }
398            }
399        }
400        Ok(Self {
401            partition_index,
402            broker_ids,
403            _unknown_tagged_fields,
404        })
405    }
406    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
407        write_i32(buf, self.partition_index);
408        if version >= 5 {
409            write_compact_array_length(buf, self.broker_ids.len() as i32);
410            for el in &self.broker_ids {
411                write_i32(buf, *el);
412            }
413        } else {
414            write_array_length(buf, self.broker_ids.len() as i32);
415            for el in &self.broker_ids {
416                write_i32(buf, *el);
417            }
418        }
419        if version >= 5 {
420            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
421            all_tags.sort_by_key(|f| f.tag);
422            write_tagged_fields(buf, &all_tags)?;
423        }
424        Ok(())
425    }
426    pub fn encoded_len(&self, version: i16) -> Result<usize> {
427        let mut len: usize = 0;
428        len += 4;
429        if version >= 5 {
430            len += compact_array_length_len(self.broker_ids.len() as i32);
431            len += self.broker_ids.len() * 4usize;
432        } else {
433            len += array_length_len();
434            len += self.broker_ids.len() * 4usize;
435        }
436        if version >= 5 {
437            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
438            all_tags.sort_by_key(|f| f.tag);
439            len += tagged_fields_len(&all_tags)?;
440        }
441        Ok(len)
442    }
443}
444#[derive(Debug, Clone, PartialEq)]
445pub struct CreatableTopicConfig {
446    /// The configuration name.
447    pub name: KafkaString,
448    /// The configuration value.
449    pub value: Option<KafkaString>,
450    pub _unknown_tagged_fields: Vec<RawTaggedField>,
451}
452impl Default for CreatableTopicConfig {
453    fn default() -> Self {
454        Self {
455            name: KafkaString::default(),
456            value: None,
457            _unknown_tagged_fields: Vec::new(),
458        }
459    }
460}
461impl CreatableTopicConfig {
462    pub fn with_name(mut self, value: KafkaString) -> Self {
463        self.name = value;
464        self
465    }
466    pub fn with_value(mut self, value: Option<KafkaString>) -> Self {
467        self.value = value;
468        self
469    }
470    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
471        let name;
472        let value;
473        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
474        if version >= 5 {
475            name = read_compact_string(buf)?;
476        } else {
477            name = read_string(buf)?;
478        }
479        if version >= 5 {
480            value = read_compact_nullable_string(buf)?;
481        } else {
482            value = read_nullable_string(buf)?;
483        }
484        if version >= 5 {
485            let tagged_fields = read_tagged_fields(buf)?;
486            for field in &tagged_fields {
487                match field.tag {
488                    _ => {
489                        _unknown_tagged_fields.push(field.clone());
490                    },
491                }
492            }
493        }
494        Ok(Self {
495            name,
496            value,
497            _unknown_tagged_fields,
498        })
499    }
500    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
501        if version >= 5 {
502            write_compact_string(buf, &self.name)?;
503        } else {
504            write_string(buf, &self.name)?;
505        }
506        if version >= 5 {
507            write_compact_nullable_string(buf, self.value.as_ref())?;
508        } else {
509            write_nullable_string(buf, self.value.as_ref())?;
510        }
511        if version >= 5 {
512            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
513            all_tags.sort_by_key(|f| f.tag);
514            write_tagged_fields(buf, &all_tags)?;
515        }
516        Ok(())
517    }
518    pub fn encoded_len(&self, version: i16) -> Result<usize> {
519        let mut len: usize = 0;
520        if version >= 5 {
521            len += compact_string_len(&self.name)?;
522        } else {
523            len += string_len(&self.name)?;
524        }
525        if version >= 5 {
526            len += compact_nullable_string_len(self.value.as_ref())?;
527        } else {
528            len += nullable_string_len(self.value.as_ref())?;
529        }
530        if version >= 5 {
531            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
532            all_tags.sort_by_key(|f| f.tag);
533            len += tagged_fields_len(&all_tags)?;
534        }
535        Ok(len)
536    }
537}