Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7    compact_string_len, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{
10    get_compact_string_borrowed, get_string_borrowed,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
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
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct DescribeLogDirsRequest<'a> {
25    pub topics: Option<Vec<DescribableLogDirTopic<'a>>>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28
29impl<'a> Default for DescribeLogDirsRequest<'a> {
30    fn default() -> Self {
31        Self {
32            topics: None,
33            unknown_tagged_fields: Default::default(),
34        }
35    }
36}
37
38impl<'a> DescribeLogDirsRequest<'a> {
39    pub fn to_owned(&self) -> crate::owned::describe_log_dirs_request::DescribeLogDirsRequest {
40        crate::owned::describe_log_dirs_request::DescribeLogDirsRequest {
41            topics: (self.topics).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
42            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
43        }
44    }
45}
46
47impl<'a> Encode for DescribeLogDirsRequest<'a> {
48    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
49        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
50            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
51        }
52        let flex = is_flexible(version);
53        if version >= 0 { { let len = (self.topics).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.topics { for it in v { it.encode(buf, version)?; } } } }
54        if flex {
55            let tagged = WriteTaggedFields::new();
56            tagged.write(buf, &self.unknown_tagged_fields);
57        }
58        Ok(())
59    }
60    fn encoded_len(&self, version: i16) -> usize {
61        let flex = is_flexible(version);
62        let mut n: usize = 0;
63        if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.topics).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
64        if flex {
65            let known_pairs: Vec<(u32, usize)> = Vec::new();
66            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
67        }
68        n
69    }
70}
71
72impl<'de> DecodeBorrow<'de> for DescribeLogDirsRequest<'de> {
73    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
74        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
75            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
76        }
77        let flex = is_flexible(version);
78        let mut out = Self::default();
79        if version >= 0 { out.topics = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribableLogDirTopic::decode_borrow(buf, version)?); } Some(v) } } }; }
80        if flex {
81            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
82                Ok(false)
83            })?;
84        }
85        Ok(out)
86    }
87}
88
89#[derive(Debug, Clone, PartialEq, Eq)]
90pub struct DescribableLogDirTopic<'a> {
91    pub topic: &'a str,
92    pub partitions: Vec<i32>,
93    pub unknown_tagged_fields: UnknownTaggedFields,
94}
95
96impl<'a> Default for DescribableLogDirTopic<'a> {
97    fn default() -> Self {
98        Self {
99            topic: "",
100            partitions: Vec::new(),
101            unknown_tagged_fields: Default::default(),
102        }
103    }
104}
105
106impl<'a> DescribableLogDirTopic<'a> {
107    pub fn to_owned(&self) -> crate::owned::describe_log_dirs_request::DescribableLogDirTopic {
108        crate::owned::describe_log_dirs_request::DescribableLogDirTopic {
109            topic: (self.topic).to_string(),
110            partitions: (self.partitions).clone(),
111            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
112        }
113    }
114}
115
116impl<'a> Encode for DescribableLogDirTopic<'a> {
117    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
118        let flex = version >= 2;
119        if version >= 0 { if flex { put_compact_string(buf, self.topic) } else { put_string(buf, self.topic) } }
120        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { put_i32(buf, *it); } } }
121        if flex {
122            let tagged = WriteTaggedFields::new();
123            tagged.write(buf, &self.unknown_tagged_fields);
124        }
125        Ok(())
126    }
127    fn encoded_len(&self, version: i16) -> usize {
128        let flex = version >= 2;
129        let mut n: usize = 0;
130        if version >= 0 { n += if flex { compact_string_len(self.topic) } else { string_len(self.topic) }; }
131        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|_| 4).sum(); prefix + body }; }
132        if flex {
133            let known_pairs: Vec<(u32, usize)> = Vec::new();
134            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
135        }
136        n
137    }
138}
139
140impl<'de> DecodeBorrow<'de> for DescribableLogDirTopic<'de> {
141    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
142        let flex = version >= 2;
143        let mut out = Self::default();
144        if version >= 0 { out.topic = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
145        if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
146        if flex {
147            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
148                Ok(false)
149            })?;
150        }
151        Ok(out)
152    }
153}