Skip to main content

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

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