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