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