Skip to main content

kacrab_protocol/generated/
describe_log_dirs_response.rs

1//! Generated from DescribeLogDirsResponse.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 DescribeLogDirsResponseData {
17    /// The duration in milliseconds for which the request was throttled due to a quota violation,
18    /// or zero if the request did not violate any quota.
19    pub throttle_time_ms: i32,
20    /// The error code, or 0 if there was no error.
21    pub error_code: i16,
22    /// The log directories.
23    pub results: Vec<DescribeLogDirsResult>,
24    pub _unknown_tagged_fields: Vec<RawTaggedField>,
25}
26impl Default for DescribeLogDirsResponseData {
27    fn default() -> Self {
28        Self {
29            throttle_time_ms: 0_i32,
30            error_code: 0_i16,
31            results: Vec::new(),
32            _unknown_tagged_fields: Vec::new(),
33        }
34    }
35}
36impl DescribeLogDirsResponseData {
37    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
38        self.throttle_time_ms = value;
39        self
40    }
41    pub fn with_error_code(mut self, value: i16) -> Self {
42        self.error_code = value;
43        self
44    }
45    pub fn with_results(mut self, value: Vec<DescribeLogDirsResult>) -> Self {
46        self.results = value;
47        self
48    }
49    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
50        if version < 1 || version > 5 {
51            return Err(UnsupportedVersion::new(35, version).into());
52        }
53        let throttle_time_ms;
54        let mut error_code = 0_i16;
55        let results;
56        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
57        throttle_time_ms = read_i32(buf)?;
58        if version >= 3 {
59            error_code = read_i16(buf)?;
60        }
61        if version >= 2 {
62            results = {
63                let len = read_compact_array_length(buf)?;
64                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
65                for _ in 0..len {
66                    arr.push(DescribeLogDirsResult::read(buf, version)?);
67                }
68                arr
69            };
70        } else {
71            results = {
72                let len = read_array_length(buf)?;
73                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
74                for _ in 0..len {
75                    arr.push(DescribeLogDirsResult::read(buf, version)?);
76                }
77                arr
78            };
79        }
80        if version >= 2 {
81            let tagged_fields = read_tagged_fields(buf)?;
82            for field in &tagged_fields {
83                match field.tag {
84                    _ => {
85                        _unknown_tagged_fields.push(field.clone());
86                    },
87                }
88            }
89        }
90        Ok(Self {
91            throttle_time_ms,
92            error_code,
93            results,
94            _unknown_tagged_fields,
95        })
96    }
97    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
98        if version < 1 || version > 5 {
99            return Err(UnsupportedVersion::new(35, version).into());
100        }
101        write_i32(buf, self.throttle_time_ms);
102        if version >= 3 {
103            write_i16(buf, self.error_code);
104        } else if self.error_code != 0_i16 {
105            return Err(UnsupportedFieldVersion::new(35, "error_code", version).into());
106        }
107        if version >= 2 {
108            write_compact_array_length(buf, self.results.len() as i32);
109            for el in &self.results {
110                el.write(buf, version)?;
111            }
112        } else {
113            write_array_length(buf, self.results.len() as i32);
114            for el in &self.results {
115                el.write(buf, version)?;
116            }
117        }
118        if version >= 2 {
119            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
120            all_tags.sort_by_key(|f| f.tag);
121            write_tagged_fields(buf, &all_tags)?;
122        }
123        Ok(())
124    }
125    pub fn encoded_len(&self, version: i16) -> Result<usize> {
126        if version < 1 || version > 5 {
127            return Err(UnsupportedVersion::new(35, version).into());
128        }
129        let mut len: usize = 0;
130        len += 4;
131        if version >= 3 {
132            len += 2;
133        } else if self.error_code != 0_i16 {
134            return Err(UnsupportedFieldVersion::new(35, "error_code", version).into());
135        }
136        if version >= 2 {
137            len += compact_array_length_len(self.results.len() as i32);
138            for el in &self.results {
139                len += el.encoded_len(version)?;
140            }
141        } else {
142            len += array_length_len();
143            for el in &self.results {
144                len += el.encoded_len(version)?;
145            }
146        }
147        if version >= 2 {
148            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
149            all_tags.sort_by_key(|f| f.tag);
150            len += tagged_fields_len(&all_tags)?;
151        }
152        Ok(len)
153    }
154}
155#[derive(Debug, Clone, PartialEq)]
156pub struct DescribeLogDirsResult {
157    /// The error code, or 0 if there was no error.
158    pub error_code: i16,
159    /// The absolute log directory path.
160    pub log_dir: KafkaString,
161    /// The topics.
162    pub topics: Vec<DescribeLogDirsTopic>,
163    /// The total size in bytes of the volume the log directory is in. This value does not include
164    /// the size of data stored in remote storage.
165    pub total_bytes: i64,
166    /// The usable size in bytes of the volume the log directory is in. This value does not include
167    /// the size of data stored in remote storage.
168    pub usable_bytes: i64,
169    /// True if this log directory is cordoned.
170    pub is_cordoned: bool,
171    pub _unknown_tagged_fields: Vec<RawTaggedField>,
172}
173impl Default for DescribeLogDirsResult {
174    fn default() -> Self {
175        Self {
176            error_code: 0_i16,
177            log_dir: KafkaString::default(),
178            topics: Vec::new(),
179            total_bytes: -1i64,
180            usable_bytes: -1i64,
181            is_cordoned: false,
182            _unknown_tagged_fields: Vec::new(),
183        }
184    }
185}
186impl DescribeLogDirsResult {
187    pub fn with_error_code(mut self, value: i16) -> Self {
188        self.error_code = value;
189        self
190    }
191    pub fn with_log_dir(mut self, value: KafkaString) -> Self {
192        self.log_dir = value;
193        self
194    }
195    pub fn with_topics(mut self, value: Vec<DescribeLogDirsTopic>) -> Self {
196        self.topics = value;
197        self
198    }
199    pub fn with_total_bytes(mut self, value: i64) -> Self {
200        self.total_bytes = value;
201        self
202    }
203    pub fn with_usable_bytes(mut self, value: i64) -> Self {
204        self.usable_bytes = value;
205        self
206    }
207    pub fn with_is_cordoned(mut self, value: bool) -> Self {
208        self.is_cordoned = value;
209        self
210    }
211    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
212        let error_code;
213        let log_dir;
214        let topics;
215        let mut total_bytes = -1i64;
216        let mut usable_bytes = -1i64;
217        let mut is_cordoned = false;
218        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
219        error_code = read_i16(buf)?;
220        if version >= 2 {
221            log_dir = read_compact_string(buf)?;
222        } else {
223            log_dir = read_string(buf)?;
224        }
225        if version >= 2 {
226            topics = {
227                let len = read_compact_array_length(buf)?;
228                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
229                for _ in 0..len {
230                    arr.push(DescribeLogDirsTopic::read(buf, version)?);
231                }
232                arr
233            };
234        } else {
235            topics = {
236                let len = read_array_length(buf)?;
237                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
238                for _ in 0..len {
239                    arr.push(DescribeLogDirsTopic::read(buf, version)?);
240                }
241                arr
242            };
243        }
244        if version >= 4 {
245            total_bytes = read_i64(buf)?;
246        }
247        if version >= 4 {
248            usable_bytes = read_i64(buf)?;
249        }
250        if version >= 5 {
251            is_cordoned = read_bool(buf)?;
252        }
253        if version >= 2 {
254            let tagged_fields = read_tagged_fields(buf)?;
255            for field in &tagged_fields {
256                match field.tag {
257                    _ => {
258                        _unknown_tagged_fields.push(field.clone());
259                    },
260                }
261            }
262        }
263        Ok(Self {
264            error_code,
265            log_dir,
266            topics,
267            total_bytes,
268            usable_bytes,
269            is_cordoned,
270            _unknown_tagged_fields,
271        })
272    }
273    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
274        write_i16(buf, self.error_code);
275        if version >= 2 {
276            write_compact_string(buf, &self.log_dir)?;
277        } else {
278            write_string(buf, &self.log_dir)?;
279        }
280        if version >= 2 {
281            write_compact_array_length(buf, self.topics.len() as i32);
282            for el in &self.topics {
283                el.write(buf, version)?;
284            }
285        } else {
286            write_array_length(buf, self.topics.len() as i32);
287            for el in &self.topics {
288                el.write(buf, version)?;
289            }
290        }
291        if version >= 4 {
292            write_i64(buf, self.total_bytes);
293        } else if self.total_bytes != -1i64 {
294            return Err(UnsupportedFieldVersion::new(35, "total_bytes", version).into());
295        }
296        if version >= 4 {
297            write_i64(buf, self.usable_bytes);
298        } else if self.usable_bytes != -1i64 {
299            return Err(UnsupportedFieldVersion::new(35, "usable_bytes", version).into());
300        }
301        if version >= 5 {
302            write_bool(buf, self.is_cordoned);
303        } else if self.is_cordoned != false {
304            return Err(UnsupportedFieldVersion::new(35, "is_cordoned", version).into());
305        }
306        if version >= 2 {
307            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
308            all_tags.sort_by_key(|f| f.tag);
309            write_tagged_fields(buf, &all_tags)?;
310        }
311        Ok(())
312    }
313    pub fn encoded_len(&self, version: i16) -> Result<usize> {
314        let mut len: usize = 0;
315        len += 2;
316        if version >= 2 {
317            len += compact_string_len(&self.log_dir)?;
318        } else {
319            len += string_len(&self.log_dir)?;
320        }
321        if version >= 2 {
322            len += compact_array_length_len(self.topics.len() as i32);
323            for el in &self.topics {
324                len += el.encoded_len(version)?;
325            }
326        } else {
327            len += array_length_len();
328            for el in &self.topics {
329                len += el.encoded_len(version)?;
330            }
331        }
332        if version >= 4 {
333            len += 8;
334        } else if self.total_bytes != -1i64 {
335            return Err(UnsupportedFieldVersion::new(35, "total_bytes", version).into());
336        }
337        if version >= 4 {
338            len += 8;
339        } else if self.usable_bytes != -1i64 {
340            return Err(UnsupportedFieldVersion::new(35, "usable_bytes", version).into());
341        }
342        if version >= 5 {
343            len += 1;
344        } else if self.is_cordoned != false {
345            return Err(UnsupportedFieldVersion::new(35, "is_cordoned", version).into());
346        }
347        if version >= 2 {
348            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
349            all_tags.sort_by_key(|f| f.tag);
350            len += tagged_fields_len(&all_tags)?;
351        }
352        Ok(len)
353    }
354}
355#[derive(Debug, Clone, PartialEq)]
356pub struct DescribeLogDirsTopic {
357    /// The topic name.
358    pub name: KafkaString,
359    /// The partitions.
360    pub partitions: Vec<DescribeLogDirsPartition>,
361    pub _unknown_tagged_fields: Vec<RawTaggedField>,
362}
363impl Default for DescribeLogDirsTopic {
364    fn default() -> Self {
365        Self {
366            name: KafkaString::default(),
367            partitions: Vec::new(),
368            _unknown_tagged_fields: Vec::new(),
369        }
370    }
371}
372impl DescribeLogDirsTopic {
373    pub fn with_name(mut self, value: KafkaString) -> Self {
374        self.name = value;
375        self
376    }
377    pub fn with_partitions(mut self, value: Vec<DescribeLogDirsPartition>) -> Self {
378        self.partitions = value;
379        self
380    }
381    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
382        let name;
383        let partitions;
384        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
385        if version >= 2 {
386            name = read_compact_string(buf)?;
387        } else {
388            name = read_string(buf)?;
389        }
390        if version >= 2 {
391            partitions = {
392                let len = read_compact_array_length(buf)?;
393                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
394                for _ in 0..len {
395                    arr.push(DescribeLogDirsPartition::read(buf, version)?);
396                }
397                arr
398            };
399        } else {
400            partitions = {
401                let len = read_array_length(buf)?;
402                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
403                for _ in 0..len {
404                    arr.push(DescribeLogDirsPartition::read(buf, version)?);
405                }
406                arr
407            };
408        }
409        if version >= 2 {
410            let tagged_fields = read_tagged_fields(buf)?;
411            for field in &tagged_fields {
412                match field.tag {
413                    _ => {
414                        _unknown_tagged_fields.push(field.clone());
415                    },
416                }
417            }
418        }
419        Ok(Self {
420            name,
421            partitions,
422            _unknown_tagged_fields,
423        })
424    }
425    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
426        if version >= 2 {
427            write_compact_string(buf, &self.name)?;
428        } else {
429            write_string(buf, &self.name)?;
430        }
431        if version >= 2 {
432            write_compact_array_length(buf, self.partitions.len() as i32);
433            for el in &self.partitions {
434                el.write(buf, version)?;
435            }
436        } else {
437            write_array_length(buf, self.partitions.len() as i32);
438            for el in &self.partitions {
439                el.write(buf, version)?;
440            }
441        }
442        if version >= 2 {
443            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
444            all_tags.sort_by_key(|f| f.tag);
445            write_tagged_fields(buf, &all_tags)?;
446        }
447        Ok(())
448    }
449    pub fn encoded_len(&self, version: i16) -> Result<usize> {
450        let mut len: usize = 0;
451        if version >= 2 {
452            len += compact_string_len(&self.name)?;
453        } else {
454            len += string_len(&self.name)?;
455        }
456        if version >= 2 {
457            len += compact_array_length_len(self.partitions.len() as i32);
458            for el in &self.partitions {
459                len += el.encoded_len(version)?;
460            }
461        } else {
462            len += array_length_len();
463            for el in &self.partitions {
464                len += el.encoded_len(version)?;
465            }
466        }
467        if version >= 2 {
468            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
469            all_tags.sort_by_key(|f| f.tag);
470            len += tagged_fields_len(&all_tags)?;
471        }
472        Ok(len)
473    }
474}
475#[derive(Debug, Clone, PartialEq)]
476pub struct DescribeLogDirsPartition {
477    /// The partition index.
478    pub partition_index: i32,
479    /// The size of the log segments in this partition in bytes.
480    pub partition_size: i64,
481    /// The lag of the log's LEO w.r.t. partition's HW (if it is the current log for the partition)
482    /// or current replica's LEO (if it is the future log for the partition).
483    pub offset_lag: i64,
484    /// True if this log is created by AlterReplicaLogDirsRequest and will replace the current log
485    /// of the replica in the future.
486    pub is_future_key: bool,
487    pub _unknown_tagged_fields: Vec<RawTaggedField>,
488}
489impl Default for DescribeLogDirsPartition {
490    fn default() -> Self {
491        Self {
492            partition_index: 0_i32,
493            partition_size: 0_i64,
494            offset_lag: 0_i64,
495            is_future_key: false,
496            _unknown_tagged_fields: Vec::new(),
497        }
498    }
499}
500impl DescribeLogDirsPartition {
501    pub fn with_partition_index(mut self, value: i32) -> Self {
502        self.partition_index = value;
503        self
504    }
505    pub fn with_partition_size(mut self, value: i64) -> Self {
506        self.partition_size = value;
507        self
508    }
509    pub fn with_offset_lag(mut self, value: i64) -> Self {
510        self.offset_lag = value;
511        self
512    }
513    pub fn with_is_future_key(mut self, value: bool) -> Self {
514        self.is_future_key = value;
515        self
516    }
517    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
518        let partition_index;
519        let partition_size;
520        let offset_lag;
521        let is_future_key;
522        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
523        partition_index = read_i32(buf)?;
524        partition_size = read_i64(buf)?;
525        offset_lag = read_i64(buf)?;
526        is_future_key = read_bool(buf)?;
527        if version >= 2 {
528            let tagged_fields = read_tagged_fields(buf)?;
529            for field in &tagged_fields {
530                match field.tag {
531                    _ => {
532                        _unknown_tagged_fields.push(field.clone());
533                    },
534                }
535            }
536        }
537        Ok(Self {
538            partition_index,
539            partition_size,
540            offset_lag,
541            is_future_key,
542            _unknown_tagged_fields,
543        })
544    }
545    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
546        write_i32(buf, self.partition_index);
547        write_i64(buf, self.partition_size);
548        write_i64(buf, self.offset_lag);
549        write_bool(buf, self.is_future_key);
550        if version >= 2 {
551            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
552            all_tags.sort_by_key(|f| f.tag);
553            write_tagged_fields(buf, &all_tags)?;
554        }
555        Ok(())
556    }
557    pub fn encoded_len(&self, version: i16) -> Result<usize> {
558        let mut len: usize = 0;
559        len += 4;
560        len += 8;
561        len += 8;
562        len += 1;
563        if version >= 2 {
564            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
565            all_tags.sort_by_key(|f| f.tag);
566            len += tagged_fields_len(&all_tags)?;
567        }
568        Ok(len)
569    }
570}