Skip to main content

kacrab_protocol/generated/
alter_replica_log_dirs_request.rs

1//! Generated from AlterReplicaLogDirsRequest.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 AlterReplicaLogDirsRequestData {
17    /// The alterations to make for each directory.
18    pub dirs: Vec<AlterReplicaLogDir>,
19    pub _unknown_tagged_fields: Vec<RawTaggedField>,
20}
21impl Default for AlterReplicaLogDirsRequestData {
22    fn default() -> Self {
23        Self {
24            dirs: Vec::new(),
25            _unknown_tagged_fields: Vec::new(),
26        }
27    }
28}
29impl AlterReplicaLogDirsRequestData {
30    pub fn with_dirs(mut self, value: Vec<AlterReplicaLogDir>) -> Self {
31        self.dirs = value;
32        self
33    }
34    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
35        if version < 1 || version > 2 {
36            return Err(UnsupportedVersion::new(34, version).into());
37        }
38        let dirs;
39        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
40        if version >= 2 {
41            dirs = {
42                let len = read_compact_array_length(buf)?;
43                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
44                for _ in 0..len {
45                    arr.push(AlterReplicaLogDir::read(buf, version)?);
46                }
47                arr
48            };
49        } else {
50            dirs = {
51                let len = read_array_length(buf)?;
52                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
53                for _ in 0..len {
54                    arr.push(AlterReplicaLogDir::read(buf, version)?);
55                }
56                arr
57            };
58        }
59        if version >= 2 {
60            let tagged_fields = read_tagged_fields(buf)?;
61            for field in &tagged_fields {
62                match field.tag {
63                    _ => {
64                        _unknown_tagged_fields.push(field.clone());
65                    },
66                }
67            }
68        }
69        Ok(Self {
70            dirs,
71            _unknown_tagged_fields,
72        })
73    }
74    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
75        if version < 1 || version > 2 {
76            return Err(UnsupportedVersion::new(34, version).into());
77        }
78        if version >= 2 {
79            write_compact_array_length(buf, self.dirs.len() as i32);
80            for el in &self.dirs {
81                el.write(buf, version)?;
82            }
83        } else {
84            write_array_length(buf, self.dirs.len() as i32);
85            for el in &self.dirs {
86                el.write(buf, version)?;
87            }
88        }
89        if version >= 2 {
90            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
91            all_tags.sort_by_key(|f| f.tag);
92            write_tagged_fields(buf, &all_tags)?;
93        }
94        Ok(())
95    }
96    pub fn encoded_len(&self, version: i16) -> Result<usize> {
97        if version < 1 || version > 2 {
98            return Err(UnsupportedVersion::new(34, version).into());
99        }
100        let mut len: usize = 0;
101        if version >= 2 {
102            len += compact_array_length_len(self.dirs.len() as i32);
103            for el in &self.dirs {
104                len += el.encoded_len(version)?;
105            }
106        } else {
107            len += array_length_len();
108            for el in &self.dirs {
109                len += el.encoded_len(version)?;
110            }
111        }
112        if version >= 2 {
113            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
114            all_tags.sort_by_key(|f| f.tag);
115            len += tagged_fields_len(&all_tags)?;
116        }
117        Ok(len)
118    }
119}
120#[derive(Debug, Clone, PartialEq)]
121pub struct AlterReplicaLogDir {
122    /// The absolute directory path.
123    pub path: KafkaString,
124    /// The topics to add to the directory.
125    pub topics: Vec<AlterReplicaLogDirTopic>,
126    pub _unknown_tagged_fields: Vec<RawTaggedField>,
127}
128impl Default for AlterReplicaLogDir {
129    fn default() -> Self {
130        Self {
131            path: KafkaString::default(),
132            topics: Vec::new(),
133            _unknown_tagged_fields: Vec::new(),
134        }
135    }
136}
137impl AlterReplicaLogDir {
138    pub fn with_path(mut self, value: KafkaString) -> Self {
139        self.path = value;
140        self
141    }
142    pub fn with_topics(mut self, value: Vec<AlterReplicaLogDirTopic>) -> Self {
143        self.topics = value;
144        self
145    }
146    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
147        let path;
148        let topics;
149        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
150        if version >= 2 {
151            path = read_compact_string(buf)?;
152        } else {
153            path = read_string(buf)?;
154        }
155        if version >= 2 {
156            topics = {
157                let len = read_compact_array_length(buf)?;
158                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
159                for _ in 0..len {
160                    arr.push(AlterReplicaLogDirTopic::read(buf, version)?);
161                }
162                arr
163            };
164        } else {
165            topics = {
166                let len = read_array_length(buf)?;
167                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
168                for _ in 0..len {
169                    arr.push(AlterReplicaLogDirTopic::read(buf, version)?);
170                }
171                arr
172            };
173        }
174        if version >= 2 {
175            let tagged_fields = read_tagged_fields(buf)?;
176            for field in &tagged_fields {
177                match field.tag {
178                    _ => {
179                        _unknown_tagged_fields.push(field.clone());
180                    },
181                }
182            }
183        }
184        Ok(Self {
185            path,
186            topics,
187            _unknown_tagged_fields,
188        })
189    }
190    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
191        if version >= 2 {
192            write_compact_string(buf, &self.path)?;
193        } else {
194            write_string(buf, &self.path)?;
195        }
196        if version >= 2 {
197            write_compact_array_length(buf, self.topics.len() as i32);
198            for el in &self.topics {
199                el.write(buf, version)?;
200            }
201        } else {
202            write_array_length(buf, self.topics.len() as i32);
203            for el in &self.topics {
204                el.write(buf, version)?;
205            }
206        }
207        if version >= 2 {
208            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
209            all_tags.sort_by_key(|f| f.tag);
210            write_tagged_fields(buf, &all_tags)?;
211        }
212        Ok(())
213    }
214    pub fn encoded_len(&self, version: i16) -> Result<usize> {
215        let mut len: usize = 0;
216        if version >= 2 {
217            len += compact_string_len(&self.path)?;
218        } else {
219            len += string_len(&self.path)?;
220        }
221        if version >= 2 {
222            len += compact_array_length_len(self.topics.len() as i32);
223            for el in &self.topics {
224                len += el.encoded_len(version)?;
225            }
226        } else {
227            len += array_length_len();
228            for el in &self.topics {
229                len += el.encoded_len(version)?;
230            }
231        }
232        if version >= 2 {
233            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
234            all_tags.sort_by_key(|f| f.tag);
235            len += tagged_fields_len(&all_tags)?;
236        }
237        Ok(len)
238    }
239}
240#[derive(Debug, Clone, PartialEq)]
241pub struct AlterReplicaLogDirTopic {
242    /// The topic name.
243    pub name: KafkaString,
244    /// The partition indexes.
245    pub partitions: Vec<i32>,
246    pub _unknown_tagged_fields: Vec<RawTaggedField>,
247}
248impl Default for AlterReplicaLogDirTopic {
249    fn default() -> Self {
250        Self {
251            name: KafkaString::default(),
252            partitions: Vec::new(),
253            _unknown_tagged_fields: Vec::new(),
254        }
255    }
256}
257impl AlterReplicaLogDirTopic {
258    pub fn with_name(mut self, value: KafkaString) -> Self {
259        self.name = value;
260        self
261    }
262    pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
263        self.partitions = value;
264        self
265    }
266    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
267        let name;
268        let partitions;
269        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
270        if version >= 2 {
271            name = read_compact_string(buf)?;
272        } else {
273            name = read_string(buf)?;
274        }
275        if version >= 2 {
276            partitions = {
277                let len = read_compact_array_length(buf)?;
278                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
279                for _ in 0..len {
280                    arr.push(read_i32(buf)?);
281                }
282                arr
283            };
284        } else {
285            partitions = {
286                let len = read_array_length(buf)?;
287                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
288                for _ in 0..len {
289                    arr.push(read_i32(buf)?);
290                }
291                arr
292            };
293        }
294        if version >= 2 {
295            let tagged_fields = read_tagged_fields(buf)?;
296            for field in &tagged_fields {
297                match field.tag {
298                    _ => {
299                        _unknown_tagged_fields.push(field.clone());
300                    },
301                }
302            }
303        }
304        Ok(Self {
305            name,
306            partitions,
307            _unknown_tagged_fields,
308        })
309    }
310    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
311        if version >= 2 {
312            write_compact_string(buf, &self.name)?;
313        } else {
314            write_string(buf, &self.name)?;
315        }
316        if version >= 2 {
317            write_compact_array_length(buf, self.partitions.len() as i32);
318            for el in &self.partitions {
319                write_i32(buf, *el);
320            }
321        } else {
322            write_array_length(buf, self.partitions.len() as i32);
323            for el in &self.partitions {
324                write_i32(buf, *el);
325            }
326        }
327        if version >= 2 {
328            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
329            all_tags.sort_by_key(|f| f.tag);
330            write_tagged_fields(buf, &all_tags)?;
331        }
332        Ok(())
333    }
334    pub fn encoded_len(&self, version: i16) -> Result<usize> {
335        let mut len: usize = 0;
336        if version >= 2 {
337            len += compact_string_len(&self.name)?;
338        } else {
339            len += string_len(&self.name)?;
340        }
341        if version >= 2 {
342            len += compact_array_length_len(self.partitions.len() as i32);
343            len += self.partitions.len() * 4usize;
344        } else {
345            len += array_length_len();
346            len += self.partitions.len() * 4usize;
347        }
348        if version >= 2 {
349            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
350            all_tags.sort_by_key(|f| f.tag);
351            len += tagged_fields_len(&all_tags)?;
352        }
353        Ok(len)
354    }
355}