Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeLogDirsRequest.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    primitives::{
7        fixed::{get_i32, put_i32},
8        string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
9        string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
10    },
11    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 35;
14pub const MIN_VERSION: i16 = 1;
15pub const MAX_VERSION: i16 = 5;
16pub const LATEST_STABLE_VERSION: i16 = 5;
17pub const FLEXIBLE_MIN: i16 = 2;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21    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}
28impl Default for DescribeLogDirsRequest<'_> {
29    fn default() -> Self {
30        Self {
31            topics: Some(Vec::new()),
32            unknown_tagged_fields: UnknownTaggedFields::default(),
33        }
34    }
35}
36impl DescribeLogDirsRequest<'_> {
37    /// # Panics
38    ///
39    /// Panics if a records field contains an invalid encoded record batch.
40    #[must_use]
41    pub fn to_owned(&self) -> crate::owned::describe_log_dirs_request::DescribeLogDirsRequest {
42        crate::owned::describe_log_dirs_request::DescribeLogDirsRequest {
43            topics: (self.topics)
44                .as_ref()
45                .map(|v| v.iter().map(DescribableLogDirTopic::to_owned).collect()),
46            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
47        }
48    }
49}
50impl Encode for DescribeLogDirsRequest<'_> {
51    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
52        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
53            return Err(ProtocolError::UnsupportedVersion {
54                api_key: API_KEY,
55                version,
56            });
57        }
58        let flex = is_flexible(version);
59        if version >= 0 {
60            {
61                let len = (self.topics).as_ref().map(Vec::len);
62                crate::primitives::array::put_nullable_array_len(buf, len, flex);
63                if let Some(v) = &self.topics {
64                    for it in v {
65                        it.encode(buf, version)?;
66                    }
67                }
68            };
69        }
70        if flex {
71            let tagged = WriteTaggedFields::new();
72            tagged.write(buf, &self.unknown_tagged_fields);
73        }
74        Ok(())
75    }
76    fn encoded_len(&self, version: i16) -> usize {
77        let flex = is_flexible(version);
78        let mut n: usize = 0;
79        if version >= 0 {
80            n += {
81                let opt: Option<&Vec<_>> = (self.topics).as_ref();
82                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
83                    opt.map(std::vec::Vec::len),
84                    flex,
85                );
86                let body: usize =
87                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
88                prefix + body
89            };
90        }
91        if flex {
92            let known_pairs: Vec<(u32, usize)> = Vec::new();
93            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
94        }
95        n
96    }
97}
98impl<'de> DecodeBorrow<'de> for DescribeLogDirsRequest<'de> {
99    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
100        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
101            return Err(ProtocolError::UnsupportedVersion {
102                api_key: API_KEY,
103                version,
104            });
105        }
106        let flex = is_flexible(version);
107        let mut out = Self::default();
108        if version >= 0 {
109            out.topics = {
110                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
111                match opt {
112                    None => None,
113                    Some(n) => {
114                        let mut v = Vec::with_capacity(n);
115                        for _ in 0..n {
116                            v.push(DescribableLogDirTopic::decode_borrow(buf, version)?);
117                        }
118                        Some(v)
119                    }
120                }
121            };
122        }
123        if flex {
124            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
125        }
126        Ok(out)
127    }
128}
129#[cfg(test)]
130impl DescribeLogDirsRequest<'_> {
131    #[must_use]
132    pub fn populated(version: i16) -> Self {
133        let mut m = Self::default();
134        if version >= 0 {
135            m.topics = Some(vec![DescribableLogDirTopic::populated(version)]);
136        }
137        m
138    }
139}
140#[derive(Debug, Clone, PartialEq, Eq, Default)]
141pub struct DescribableLogDirTopic<'a> {
142    pub topic: &'a str,
143    pub partitions: Vec<i32>,
144    pub unknown_tagged_fields: UnknownTaggedFields,
145}
146impl DescribableLogDirTopic<'_> {
147    /// # Panics
148    ///
149    /// Panics if a records field contains an invalid encoded record batch.
150    #[must_use]
151    pub fn to_owned(&self) -> crate::owned::describe_log_dirs_request::DescribableLogDirTopic {
152        crate::owned::describe_log_dirs_request::DescribableLogDirTopic {
153            topic: (self.topic).to_string(),
154            partitions: (self.partitions).clone(),
155            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
156        }
157    }
158}
159impl Encode for DescribableLogDirTopic<'_> {
160    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
161        let flex = version >= 2;
162        if version >= 0 {
163            if flex {
164                let () = put_compact_string(buf, self.topic);
165            } else {
166                let () = put_string(buf, self.topic);
167            }
168        }
169        if version >= 0 {
170            {
171                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
172                for it in &self.partitions {
173                    put_i32(buf, *it);
174                }
175            };
176        }
177        if flex {
178            let tagged = WriteTaggedFields::new();
179            tagged.write(buf, &self.unknown_tagged_fields);
180        }
181        Ok(())
182    }
183    fn encoded_len(&self, version: i16) -> usize {
184        let flex = version >= 2;
185        let mut n: usize = 0;
186        if version >= 0 {
187            n += if flex {
188                compact_string_len(self.topic)
189            } else {
190                string_len(self.topic)
191            };
192        }
193        if version >= 0 {
194            n += {
195                let prefix =
196                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
197                let body: usize = (self.partitions).iter().map(|_| 4).sum();
198                prefix + body
199            };
200        }
201        if flex {
202            let known_pairs: Vec<(u32, usize)> = Vec::new();
203            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
204        }
205        n
206    }
207}
208impl<'de> DecodeBorrow<'de> for DescribableLogDirTopic<'de> {
209    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
210        let flex = version >= 2;
211        let mut out = Self::default();
212        if version >= 0 {
213            out.topic = if flex {
214                get_compact_string_borrowed(buf)?
215            } else {
216                get_string_borrowed(buf)?
217            };
218        }
219        if version >= 0 {
220            out.partitions = {
221                let n = crate::primitives::array::get_array_len(buf, flex)?;
222                let mut v = Vec::with_capacity(n);
223                for _ in 0..n {
224                    v.push(get_i32(buf)?);
225                }
226                v
227            };
228        }
229        if flex {
230            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
231        }
232        Ok(out)
233    }
234}
235#[cfg(test)]
236impl DescribableLogDirTopic<'_> {
237    #[must_use]
238    pub fn populated(version: i16) -> Self {
239        let mut m = Self::default();
240        if version >= 0 {
241            m.topic = "x";
242        }
243        if version >= 0 {
244            m.partitions = vec![1i32];
245        }
246        m
247    }
248}