crabka_protocol/opt/rustwide/workdir/generated/
DescribeTopicPartitionsRequest.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i8, get_i32, put_i32};
6use crate::primitives::string_bytes::{
7 compact_string_len, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 75;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const FLEXIBLE_MIN: i16 = 0;
17
18#[inline]
19fn is_flexible(version: i16) -> bool {
20 version >= FLEXIBLE_MIN
21}
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: Default::default(),
37 }
38 }
39}
40impl DescribeTopicPartitionsRequest<'_> {
41 pub fn to_owned(
42 &self,
43 ) -> crate::owned::describe_topic_partitions_request::DescribeTopicPartitionsRequest {
44 crate::owned::describe_topic_partitions_request::DescribeTopicPartitionsRequest {
45 topics: (self.topics).iter().map(TopicRequest::to_owned).collect(),
46 response_partition_limit: (self.response_partition_limit),
47 cursor: (self.cursor).as_ref().map(Cursor::to_owned),
48 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
49 }
50 }
51}
52impl Encode for DescribeTopicPartitionsRequest<'_> {
53 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
54 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
55 return Err(ProtocolError::UnsupportedVersion {
56 api_key: API_KEY,
57 version,
58 });
59 }
60 let flex = is_flexible(version);
61 if version >= 0 {
62 {
63 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
64 for it in &self.topics {
65 it.encode(buf, version)?;
66 }
67 }
68 }
69 if version >= 0 {
70 put_i32(buf, self.response_partition_limit);
71 }
72 if version >= 0 {
73 match &self.cursor {
74 None => {
75 buf.put_i8(-1);
76 }
77 Some(v) => {
78 buf.put_i8(1);
79 v.encode(buf, version)?;
80 }
81 }
82 }
83 if flex {
84 let tagged = WriteTaggedFields::new();
85 tagged.write(buf, &self.unknown_tagged_fields);
86 }
87 Ok(())
88 }
89 fn encoded_len(&self, version: i16) -> usize {
90 let flex = is_flexible(version);
91 let mut n: usize = 0;
92 if version >= 0 {
93 n += {
94 let prefix =
95 crate::primitives::array::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 = crate::primitives::array::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 pub fn to_owned(&self) -> crate::owned::describe_topic_partitions_request::TopicRequest {
173 crate::owned::describe_topic_partitions_request::TopicRequest {
174 name: (self.name).to_string(),
175 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
176 }
177 }
178}
179impl Encode for TopicRequest<'_> {
180 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
181 let flex = version >= 0;
182 if version >= 0 {
183 if flex {
184 put_compact_string(buf, self.name);
185 } else {
186 put_string(buf, self.name);
187 }
188 }
189 if flex {
190 let tagged = WriteTaggedFields::new();
191 tagged.write(buf, &self.unknown_tagged_fields);
192 }
193 Ok(())
194 }
195 fn encoded_len(&self, version: i16) -> usize {
196 let flex = version >= 0;
197 let mut n: usize = 0;
198 if version >= 0 {
199 n += if flex {
200 compact_string_len(self.name)
201 } else {
202 string_len(self.name)
203 };
204 }
205 if flex {
206 let known_pairs: Vec<(u32, usize)> = Vec::new();
207 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
208 }
209 n
210 }
211}
212impl<'de> DecodeBorrow<'de> for TopicRequest<'de> {
213 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
214 let flex = version >= 0;
215 let mut out = Self::default();
216 if version >= 0 {
217 out.name = if flex {
218 get_compact_string_borrowed(buf)?
219 } else {
220 get_string_borrowed(buf)?
221 };
222 }
223 if flex {
224 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
225 }
226 Ok(out)
227 }
228}
229#[cfg(test)]
230impl TopicRequest<'_> {
231 #[must_use]
232 pub fn populated(version: i16) -> Self {
233 let mut m = Self::default();
234 if version >= 0 {
235 m.name = "x";
236 }
237 m
238 }
239}
240#[derive(Debug, Clone, PartialEq, Eq, Default)]
241pub struct Cursor<'a> {
242 pub topic_name: &'a str,
243 pub partition_index: i32,
244 pub unknown_tagged_fields: UnknownTaggedFields,
245}
246impl Cursor<'_> {
247 pub fn to_owned(&self) -> crate::owned::describe_topic_partitions_request::Cursor {
248 crate::owned::describe_topic_partitions_request::Cursor {
249 topic_name: (self.topic_name).to_string(),
250 partition_index: (self.partition_index),
251 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
252 }
253 }
254}
255impl Encode for Cursor<'_> {
256 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
257 let flex = version >= 0;
258 if version >= 0 {
259 if flex {
260 put_compact_string(buf, self.topic_name);
261 } else {
262 put_string(buf, self.topic_name);
263 }
264 }
265 if version >= 0 {
266 put_i32(buf, self.partition_index);
267 }
268 if flex {
269 let tagged = WriteTaggedFields::new();
270 tagged.write(buf, &self.unknown_tagged_fields);
271 }
272 Ok(())
273 }
274 fn encoded_len(&self, version: i16) -> usize {
275 let flex = version >= 0;
276 let mut n: usize = 0;
277 if version >= 0 {
278 n += if flex {
279 compact_string_len(self.topic_name)
280 } else {
281 string_len(self.topic_name)
282 };
283 }
284 if version >= 0 {
285 n += 4;
286 }
287 if flex {
288 let known_pairs: Vec<(u32, usize)> = Vec::new();
289 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
290 }
291 n
292 }
293}
294impl<'de> DecodeBorrow<'de> for Cursor<'de> {
295 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
296 let flex = version >= 0;
297 let mut out = Self::default();
298 if version >= 0 {
299 out.topic_name = if flex {
300 get_compact_string_borrowed(buf)?
301 } else {
302 get_string_borrowed(buf)?
303 };
304 }
305 if version >= 0 {
306 out.partition_index = get_i32(buf)?;
307 }
308 if flex {
309 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
310 }
311 Ok(out)
312 }
313}
314#[cfg(test)]
315impl Cursor<'_> {
316 #[must_use]
317 pub fn populated(version: i16) -> Self {
318 let mut m = Self::default();
319 if version >= 0 {
320 m.topic_name = "x";
321 }
322 if version >= 0 {
323 m.partition_index = 1i32;
324 }
325 m
326 }
327}