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