Skip to main content

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