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