Skip to main content

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

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