Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeLogDirsResponse.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    owned::describe_log_dirs_response,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_bool, get_i16, get_i32, get_i64, put_bool, put_i16, put_i32, put_i64},
10        string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
11        string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
12    },
13    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
14};
15pub const API_KEY: i16 = 35;
16pub const MIN_VERSION: i16 = 1;
17pub const MAX_VERSION: i16 = 5;
18pub const FLEXIBLE_MIN: i16 = 2;
19#[inline]
20#[must_use]
21pub fn is_flexible(version: i16) -> bool {
22    version >= FLEXIBLE_MIN
23}
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct DescribeLogDirsResponse<'a> {
26    pub throttle_time_ms: i32,
27    pub error_code: i16,
28    pub results: Vec<DescribeLogDirsResult<'a>>,
29    pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl DescribeLogDirsResponse<'_> {
32    #[must_use]
33    pub fn to_owned(&self) -> describe_log_dirs_response::DescribeLogDirsResponse {
34        describe_log_dirs_response::DescribeLogDirsResponse {
35            throttle_time_ms: (self.throttle_time_ms),
36            error_code: (self.error_code),
37            results: (self.results)
38                .iter()
39                .map(DescribeLogDirsResult::to_owned)
40                .collect(),
41            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
42        }
43    }
44}
45impl Encode for DescribeLogDirsResponse<'_> {
46    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
47        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
48            return Err(ProtocolError::UnsupportedVersion {
49                api_key: API_KEY,
50                version,
51            });
52        }
53        let flex = is_flexible(version);
54        if version >= 0 {
55            put_i32(buf, self.throttle_time_ms);
56        }
57        if version >= 3 {
58            put_i16(buf, self.error_code);
59        }
60        if version >= 0 {
61            {
62                put_array_len(buf, (self.results).len(), flex)?;
63                for it in &self.results {
64                    it.encode(buf, version)?;
65                }
66            }
67        }
68        if flex {
69            let tagged = WriteTaggedFields::new();
70            tagged.write(buf, &self.unknown_tagged_fields)?;
71        }
72        Ok(())
73    }
74    fn encoded_len(&self, version: i16) -> usize {
75        let flex = is_flexible(version);
76        let mut n: usize = 0;
77        if version >= 0 {
78            n += 4;
79        }
80        if version >= 3 {
81            n += 2;
82        }
83        if version >= 0 {
84            n += {
85                let prefix = array_len_prefix_len((self.results).len(), flex);
86                let body: usize = (self.results)
87                    .iter()
88                    .map(|it| it.encoded_len(version))
89                    .sum();
90                prefix + body
91            };
92        }
93        if flex {
94            let known_pairs: Vec<(u32, usize)> = Vec::new();
95            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
96        }
97        n
98    }
99}
100impl<'de> DecodeBorrow<'de> for DescribeLogDirsResponse<'de> {
101    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
102        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
103            return Err(ProtocolError::UnsupportedVersion {
104                api_key: API_KEY,
105                version,
106            });
107        }
108        let flex = is_flexible(version);
109        let mut out = Self::default();
110        if version >= 0 {
111            out.throttle_time_ms = get_i32(buf)?;
112        }
113        if version >= 3 {
114            out.error_code = get_i16(buf)?;
115        }
116        if version >= 0 {
117            out.results = {
118                let n = get_array_len(buf, flex)?;
119                let mut v = Vec::with_capacity(n);
120                for _ in 0..n {
121                    v.push(DescribeLogDirsResult::decode_borrow(buf, version)?);
122                }
123                v
124            };
125        }
126        if flex {
127            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
128        }
129        Ok(out)
130    }
131}
132#[cfg(test)]
133impl DescribeLogDirsResponse<'_> {
134    #[must_use]
135    pub fn populated(version: i16) -> Self {
136        let mut m = Self::default();
137        if version >= 0 {
138            m.throttle_time_ms = 1i32;
139        }
140        if version >= 3 {
141            m.error_code = 1i16;
142        }
143        if version >= 0 {
144            m.results = vec![DescribeLogDirsResult::populated(version)];
145        }
146        m
147    }
148}
149#[derive(Debug, Clone, PartialEq, Eq)]
150pub struct DescribeLogDirsResult<'a> {
151    pub error_code: i16,
152    pub log_dir: &'a str,
153    pub topics: Vec<DescribeLogDirsTopic<'a>>,
154    pub total_bytes: i64,
155    pub usable_bytes: i64,
156    pub is_cordoned: bool,
157    pub unknown_tagged_fields: UnknownTaggedFields,
158}
159impl Default for DescribeLogDirsResult<'_> {
160    fn default() -> Self {
161        Self {
162            error_code: 0i16,
163            log_dir: "",
164            topics: Vec::new(),
165            total_bytes: -1i64,
166            usable_bytes: -1i64,
167            is_cordoned: false,
168            unknown_tagged_fields: UnknownTaggedFields::default(),
169        }
170    }
171}
172impl DescribeLogDirsResult<'_> {
173    #[must_use]
174    pub fn to_owned(&self) -> describe_log_dirs_response::DescribeLogDirsResult {
175        describe_log_dirs_response::DescribeLogDirsResult {
176            error_code: (self.error_code),
177            log_dir: (self.log_dir).to_owned(),
178            topics: (self.topics)
179                .iter()
180                .map(DescribeLogDirsTopic::to_owned)
181                .collect(),
182            total_bytes: (self.total_bytes),
183            usable_bytes: (self.usable_bytes),
184            is_cordoned: (self.is_cordoned),
185            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
186        }
187    }
188}
189impl Encode for DescribeLogDirsResult<'_> {
190    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
191        let flex = version >= 2;
192        if version >= 0 {
193            put_i16(buf, self.error_code);
194        }
195        if version >= 0 {
196            if flex {
197                put_compact_string(buf, self.log_dir)?;
198            } else {
199                put_string(buf, self.log_dir)?;
200            }
201        }
202        if version >= 0 {
203            {
204                put_array_len(buf, (self.topics).len(), flex)?;
205                for it in &self.topics {
206                    it.encode(buf, version)?;
207                }
208            }
209        }
210        if version >= 4 {
211            put_i64(buf, self.total_bytes);
212        }
213        if version >= 4 {
214            put_i64(buf, self.usable_bytes);
215        }
216        if version >= 5 {
217            put_bool(buf, self.is_cordoned);
218        }
219        if flex {
220            let tagged = WriteTaggedFields::new();
221            tagged.write(buf, &self.unknown_tagged_fields)?;
222        }
223        Ok(())
224    }
225    fn encoded_len(&self, version: i16) -> usize {
226        let flex = version >= 2;
227        let mut n: usize = 0;
228        if version >= 0 {
229            n += 2;
230        }
231        if version >= 0 {
232            n += if flex {
233                compact_string_len(self.log_dir)
234            } else {
235                string_len(self.log_dir)
236            };
237        }
238        if version >= 0 {
239            n += {
240                let prefix = array_len_prefix_len((self.topics).len(), flex);
241                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
242                prefix + body
243            };
244        }
245        if version >= 4 {
246            n += 8;
247        }
248        if version >= 4 {
249            n += 8;
250        }
251        if version >= 5 {
252            n += 1;
253        }
254        if flex {
255            let known_pairs: Vec<(u32, usize)> = Vec::new();
256            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
257        }
258        n
259    }
260}
261impl<'de> DecodeBorrow<'de> for DescribeLogDirsResult<'de> {
262    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
263        let flex = version >= 2;
264        let mut out = Self::default();
265        if version >= 0 {
266            out.error_code = get_i16(buf)?;
267        }
268        if version >= 0 {
269            out.log_dir = if flex {
270                get_compact_string_borrowed(buf)?
271            } else {
272                get_string_borrowed(buf)?
273            };
274        }
275        if version >= 0 {
276            out.topics = {
277                let n = get_array_len(buf, flex)?;
278                let mut v = Vec::with_capacity(n);
279                for _ in 0..n {
280                    v.push(DescribeLogDirsTopic::decode_borrow(buf, version)?);
281                }
282                v
283            };
284        }
285        if version >= 4 {
286            out.total_bytes = get_i64(buf)?;
287        }
288        if version >= 4 {
289            out.usable_bytes = get_i64(buf)?;
290        }
291        if version >= 5 {
292            out.is_cordoned = get_bool(buf)?;
293        }
294        if flex {
295            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
296        }
297        Ok(out)
298    }
299}
300#[cfg(test)]
301impl DescribeLogDirsResult<'_> {
302    #[must_use]
303    pub fn populated(version: i16) -> Self {
304        let mut m = Self::default();
305        if version >= 0 {
306            m.error_code = 1i16;
307        }
308        if version >= 0 {
309            m.log_dir = "x";
310        }
311        if version >= 0 {
312            m.topics = vec![DescribeLogDirsTopic::populated(version)];
313        }
314        if version >= 4 {
315            m.total_bytes = 1i64;
316        }
317        if version >= 4 {
318            m.usable_bytes = 1i64;
319        }
320        if version >= 5 {
321            m.is_cordoned = true;
322        }
323        m
324    }
325}
326#[derive(Debug, Clone, PartialEq, Eq, Default)]
327pub struct DescribeLogDirsTopic<'a> {
328    pub name: &'a str,
329    pub partitions: Vec<DescribeLogDirsPartition>,
330    pub unknown_tagged_fields: UnknownTaggedFields,
331}
332impl DescribeLogDirsTopic<'_> {
333    #[must_use]
334    pub fn to_owned(&self) -> describe_log_dirs_response::DescribeLogDirsTopic {
335        describe_log_dirs_response::DescribeLogDirsTopic {
336            name: (self.name).to_owned(),
337            partitions: (self.partitions)
338                .iter()
339                .map(DescribeLogDirsPartition::to_owned)
340                .collect(),
341            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
342        }
343    }
344}
345impl Encode for DescribeLogDirsTopic<'_> {
346    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
347        let flex = version >= 2;
348        if version >= 0 {
349            if flex {
350                put_compact_string(buf, self.name)?;
351            } else {
352                put_string(buf, self.name)?;
353            }
354        }
355        if version >= 0 {
356            {
357                put_array_len(buf, (self.partitions).len(), flex)?;
358                for it in &self.partitions {
359                    it.encode(buf, version)?;
360                }
361            }
362        }
363        if flex {
364            let tagged = WriteTaggedFields::new();
365            tagged.write(buf, &self.unknown_tagged_fields)?;
366        }
367        Ok(())
368    }
369    fn encoded_len(&self, version: i16) -> usize {
370        let flex = version >= 2;
371        let mut n: usize = 0;
372        if version >= 0 {
373            n += if flex {
374                compact_string_len(self.name)
375            } else {
376                string_len(self.name)
377            };
378        }
379        if version >= 0 {
380            n += {
381                let prefix = array_len_prefix_len((self.partitions).len(), flex);
382                let body: usize = (self.partitions)
383                    .iter()
384                    .map(|it| it.encoded_len(version))
385                    .sum();
386                prefix + body
387            };
388        }
389        if flex {
390            let known_pairs: Vec<(u32, usize)> = Vec::new();
391            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
392        }
393        n
394    }
395}
396impl<'de> DecodeBorrow<'de> for DescribeLogDirsTopic<'de> {
397    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
398        let flex = version >= 2;
399        let mut out = Self::default();
400        if version >= 0 {
401            out.name = if flex {
402                get_compact_string_borrowed(buf)?
403            } else {
404                get_string_borrowed(buf)?
405            };
406        }
407        if version >= 0 {
408            out.partitions = {
409                let n = get_array_len(buf, flex)?;
410                let mut v = Vec::with_capacity(n);
411                for _ in 0..n {
412                    v.push(DescribeLogDirsPartition::decode_borrow(buf, version)?);
413                }
414                v
415            };
416        }
417        if flex {
418            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
419        }
420        Ok(out)
421    }
422}
423#[cfg(test)]
424impl DescribeLogDirsTopic<'_> {
425    #[must_use]
426    pub fn populated(version: i16) -> Self {
427        let mut m = Self::default();
428        if version >= 0 {
429            m.name = "x";
430        }
431        if version >= 0 {
432            m.partitions = vec![DescribeLogDirsPartition::populated(version)];
433        }
434        m
435    }
436}
437#[derive(Debug, Clone, PartialEq, Eq, Default)]
438pub struct DescribeLogDirsPartition {
439    pub partition_index: i32,
440    pub partition_size: i64,
441    pub offset_lag: i64,
442    pub is_future_key: bool,
443    pub unknown_tagged_fields: UnknownTaggedFields,
444}
445impl DescribeLogDirsPartition {
446    #[must_use]
447    pub fn to_owned(&self) -> describe_log_dirs_response::DescribeLogDirsPartition {
448        describe_log_dirs_response::DescribeLogDirsPartition {
449            partition_index: (self.partition_index),
450            partition_size: (self.partition_size),
451            offset_lag: (self.offset_lag),
452            is_future_key: (self.is_future_key),
453            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
454        }
455    }
456}
457impl Encode for DescribeLogDirsPartition {
458    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
459        let flex = version >= 2;
460        if version >= 0 {
461            put_i32(buf, self.partition_index);
462        }
463        if version >= 0 {
464            put_i64(buf, self.partition_size);
465        }
466        if version >= 0 {
467            put_i64(buf, self.offset_lag);
468        }
469        if version >= 0 {
470            put_bool(buf, self.is_future_key);
471        }
472        if flex {
473            let tagged = WriteTaggedFields::new();
474            tagged.write(buf, &self.unknown_tagged_fields)?;
475        }
476        Ok(())
477    }
478    fn encoded_len(&self, version: i16) -> usize {
479        let flex = version >= 2;
480        let mut n: usize = 0;
481        if version >= 0 {
482            n += 4;
483        }
484        if version >= 0 {
485            n += 8;
486        }
487        if version >= 0 {
488            n += 8;
489        }
490        if version >= 0 {
491            n += 1;
492        }
493        if flex {
494            let known_pairs: Vec<(u32, usize)> = Vec::new();
495            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
496        }
497        n
498    }
499}
500impl<'de> DecodeBorrow<'de> for DescribeLogDirsPartition {
501    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
502        let flex = version >= 2;
503        let mut out = Self::default();
504        if version >= 0 {
505            out.partition_index = get_i32(buf)?;
506        }
507        if version >= 0 {
508            out.partition_size = get_i64(buf)?;
509        }
510        if version >= 0 {
511            out.offset_lag = get_i64(buf)?;
512        }
513        if version >= 0 {
514            out.is_future_key = get_bool(buf)?;
515        }
516        if flex {
517            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
518        }
519        Ok(out)
520    }
521}
522#[cfg(test)]
523impl DescribeLogDirsPartition {
524    #[must_use]
525    pub fn populated(version: i16) -> Self {
526        let mut m = Self::default();
527        if version >= 0 {
528            m.partition_index = 1i32;
529        }
530        if version >= 0 {
531            m.partition_size = 1i64;
532        }
533        if version >= 0 {
534            m.offset_lag = 1i64;
535        }
536        if version >= 0 {
537            m.is_future_key = true;
538        }
539        m
540    }
541}