Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use crate::primitives::fixed::{get_i8, 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 = 75;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 0;
13pub const FLEXIBLE_MIN: i16 = 0;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub struct DescribeTopicPartitionsRequest<'a> {
20    pub topics: Vec<TopicRequest<'a>>,
21    pub response_partition_limit: i32,
22    pub cursor: Option<Cursor<'a>>,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Default for DescribeTopicPartitionsRequest<'_> {
26    fn default() -> Self {
27        Self {
28            topics: Vec::new(),
29            response_partition_limit: 2_000i32,
30            cursor: None,
31            unknown_tagged_fields: Default::default(),
32        }
33    }
34}
35impl DescribeTopicPartitionsRequest<'_> {
36    pub fn to_owned(
37        &self,
38    ) -> crate::owned::describe_topic_partitions_request::DescribeTopicPartitionsRequest {
39        crate::owned::describe_topic_partitions_request::DescribeTopicPartitionsRequest {
40            topics: (self.topics).iter().map(TopicRequest::to_owned).collect(),
41            response_partition_limit: (self.response_partition_limit),
42            cursor: (self.cursor).as_ref().map(Cursor::to_owned),
43            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
44        }
45    }
46}
47impl Encode for DescribeTopicPartitionsRequest<'_> {
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 {
51                api_key: API_KEY,
52                version,
53            });
54        }
55        let flex = is_flexible(version);
56        if version >= 0 {
57            {
58                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
59                for it in &self.topics {
60                    it.encode(buf, version)?;
61                }
62            }
63        }
64        if version >= 0 {
65            put_i32(buf, self.response_partition_limit);
66        }
67        if version >= 0 {
68            match &self.cursor {
69                None => {
70                    buf.put_i8(-1);
71                }
72                Some(v) => {
73                    buf.put_i8(1);
74                    v.encode(buf, version)?;
75                }
76            }
77        }
78        if flex {
79            let tagged = WriteTaggedFields::new();
80            tagged.write(buf, &self.unknown_tagged_fields);
81        }
82        Ok(())
83    }
84    fn encoded_len(&self, version: i16) -> usize {
85        let flex = is_flexible(version);
86        let mut n: usize = 0;
87        if version >= 0 {
88            n += {
89                let prefix =
90                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
91                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
92                prefix + body
93            };
94        }
95        if version >= 0 {
96            n += 4;
97        }
98        if version >= 0 {
99            n += 1 + self.cursor.as_ref().map_or(0, |v| v.encoded_len(version));
100        }
101        if flex {
102            let known_pairs: Vec<(u32, usize)> = Vec::new();
103            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
104        }
105        n
106    }
107}
108impl<'de> DecodeBorrow<'de> for DescribeTopicPartitionsRequest<'de> {
109    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
110        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
111            return Err(ProtocolError::UnsupportedVersion {
112                api_key: API_KEY,
113                version,
114            });
115        }
116        let flex = is_flexible(version);
117        let mut out = Self::default();
118        if version >= 0 {
119            out.topics = {
120                let n = crate::primitives::array::get_array_len(buf, flex)?;
121                let mut v = Vec::with_capacity(n);
122                for _ in 0..n {
123                    v.push(TopicRequest::decode_borrow(buf, version)?);
124                }
125                v
126            };
127        }
128        if version >= 0 {
129            out.response_partition_limit = get_i32(buf)?;
130        }
131        if version >= 0 {
132            out.cursor = if get_i8(buf)? < 0 {
133                None
134            } else {
135                Some(Cursor::decode_borrow(buf, version)?)
136            };
137        }
138        if flex {
139            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
140        }
141        Ok(out)
142    }
143}
144#[cfg(test)]
145impl DescribeTopicPartitionsRequest<'_> {
146    #[must_use]
147    pub fn populated(version: i16) -> Self {
148        let mut m = Self::default();
149        if version >= 0 {
150            m.topics = vec![TopicRequest::populated(version)];
151        }
152        if version >= 0 {
153            m.response_partition_limit = 1i32;
154        }
155        if version >= 0 {
156            m.cursor = Some(Cursor::populated(version));
157        }
158        m
159    }
160}
161#[derive(Debug, Clone, PartialEq, Eq, Default)]
162pub struct TopicRequest<'a> {
163    pub name: &'a str,
164    pub unknown_tagged_fields: UnknownTaggedFields,
165}
166impl TopicRequest<'_> {
167    pub fn to_owned(&self) -> crate::owned::describe_topic_partitions_request::TopicRequest {
168        crate::owned::describe_topic_partitions_request::TopicRequest {
169            name: (self.name).to_string(),
170            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
171        }
172    }
173}
174impl Encode for TopicRequest<'_> {
175    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
176        let flex = version >= 0;
177        if version >= 0 {
178            if flex {
179                put_compact_string(buf, self.name);
180            } else {
181                put_string(buf, self.name);
182            }
183        }
184        if flex {
185            let tagged = WriteTaggedFields::new();
186            tagged.write(buf, &self.unknown_tagged_fields);
187        }
188        Ok(())
189    }
190    fn encoded_len(&self, version: i16) -> usize {
191        let flex = version >= 0;
192        let mut n: usize = 0;
193        if version >= 0 {
194            n += if flex {
195                compact_string_len(self.name)
196            } else {
197                string_len(self.name)
198            };
199        }
200        if flex {
201            let known_pairs: Vec<(u32, usize)> = Vec::new();
202            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
203        }
204        n
205    }
206}
207impl<'de> DecodeBorrow<'de> for TopicRequest<'de> {
208    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
209        let flex = version >= 0;
210        let mut out = Self::default();
211        if version >= 0 {
212            out.name = if flex {
213                get_compact_string_borrowed(buf)?
214            } else {
215                get_string_borrowed(buf)?
216            };
217        }
218        if flex {
219            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
220        }
221        Ok(out)
222    }
223}
224#[cfg(test)]
225impl TopicRequest<'_> {
226    #[must_use]
227    pub fn populated(version: i16) -> Self {
228        let mut m = Self::default();
229        if version >= 0 {
230            m.name = "x";
231        }
232        m
233    }
234}
235#[derive(Debug, Clone, PartialEq, Eq, Default)]
236pub struct Cursor<'a> {
237    pub topic_name: &'a str,
238    pub partition_index: i32,
239    pub unknown_tagged_fields: UnknownTaggedFields,
240}
241impl Cursor<'_> {
242    pub fn to_owned(&self) -> crate::owned::describe_topic_partitions_request::Cursor {
243        crate::owned::describe_topic_partitions_request::Cursor {
244            topic_name: (self.topic_name).to_string(),
245            partition_index: (self.partition_index),
246            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
247        }
248    }
249}
250impl Encode for Cursor<'_> {
251    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
252        let flex = version >= 0;
253        if version >= 0 {
254            if flex {
255                put_compact_string(buf, self.topic_name);
256            } else {
257                put_string(buf, self.topic_name);
258            }
259        }
260        if version >= 0 {
261            put_i32(buf, self.partition_index);
262        }
263        if flex {
264            let tagged = WriteTaggedFields::new();
265            tagged.write(buf, &self.unknown_tagged_fields);
266        }
267        Ok(())
268    }
269    fn encoded_len(&self, version: i16) -> usize {
270        let flex = version >= 0;
271        let mut n: usize = 0;
272        if version >= 0 {
273            n += if flex {
274                compact_string_len(self.topic_name)
275            } else {
276                string_len(self.topic_name)
277            };
278        }
279        if version >= 0 {
280            n += 4;
281        }
282        if flex {
283            let known_pairs: Vec<(u32, usize)> = Vec::new();
284            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
285        }
286        n
287    }
288}
289impl<'de> DecodeBorrow<'de> for Cursor<'de> {
290    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
291        let flex = version >= 0;
292        let mut out = Self::default();
293        if version >= 0 {
294            out.topic_name = if flex {
295                get_compact_string_borrowed(buf)?
296            } else {
297                get_string_borrowed(buf)?
298            };
299        }
300        if version >= 0 {
301            out.partition_index = get_i32(buf)?;
302        }
303        if flex {
304            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
305        }
306        Ok(out)
307    }
308}
309#[cfg(test)]
310impl Cursor<'_> {
311    #[must_use]
312    pub fn populated(version: i16) -> Self {
313        let mut m = Self::default();
314        if version >= 0 {
315            m.topic_name = "x";
316        }
317        if version >= 0 {
318            m.partition_index = 1i32;
319        }
320        m
321    }
322}