krabka_protocol/opt/rustwide/workdir/generated/
ListPartitionReassignmentsResponse.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_i16, get_i32, put_i16, put_i32},
10 string_bytes::{
11 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
12 get_compact_string_owned, get_nullable_string_owned, get_string_owned,
13 nullable_string_len, put_compact_nullable_string, put_compact_string,
14 put_nullable_string, put_string, string_len,
15 },
16 },
17 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 46;
20pub const MIN_VERSION: i16 = 0;
21pub const MAX_VERSION: i16 = 0;
22pub const FLEXIBLE_MIN: i16 = 0;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26 version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct ListPartitionReassignmentsResponse {
30 pub throttle_time_ms: i32,
31 pub error_code: i16,
32 pub error_message: Option<String>,
33 pub topics: Vec<OngoingTopicReassignment>,
34 pub unknown_tagged_fields: UnknownTaggedFields,
35}
36impl Default for ListPartitionReassignmentsResponse {
37 fn default() -> Self {
38 Self {
39 throttle_time_ms: 0i32,
40 error_code: 0i16,
41 error_message: Some(String::new()),
42 topics: Vec::new(),
43 unknown_tagged_fields: UnknownTaggedFields::default(),
44 }
45 }
46}
47impl Encode for ListPartitionReassignmentsResponse {
48 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
49 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
50 return Err(ProtocolError::UnsupportedVersion {
51 api_key: API_KEY,
52 version,
53 });
54 }
55 let flex = is_flexible(version);
56 if version >= 0 {
57 put_i32(buf, self.throttle_time_ms);
58 }
59 if version >= 0 {
60 put_i16(buf, self.error_code);
61 }
62 if version >= 0 {
63 if flex {
64 put_compact_nullable_string(buf, self.error_message.as_deref())?;
65 } else {
66 put_nullable_string(buf, self.error_message.as_deref())?;
67 }
68 }
69 if version >= 0 {
70 {
71 put_array_len(buf, (self.topics).len(), flex)?;
72 for it in &self.topics {
73 it.encode(buf, version)?;
74 }
75 }
76 }
77 if flex {
78 let tagged = WriteTaggedFields::new();
79 tagged.write(buf, &self.unknown_tagged_fields)?;
80 }
81 Ok(())
82 }
83 fn encoded_len(&self, version: i16) -> usize {
84 let flex = is_flexible(version);
85 let mut n: usize = 0;
86 if version >= 0 {
87 n += 4;
88 }
89 if version >= 0 {
90 n += 2;
91 }
92 if version >= 0 {
93 n += if flex {
94 compact_nullable_string_len(self.error_message.as_deref())
95 } else {
96 nullable_string_len(self.error_message.as_deref())
97 };
98 }
99 if version >= 0 {
100 n += {
101 let prefix = array_len_prefix_len((self.topics).len(), flex);
102 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
103 prefix + body
104 };
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 Decode<'_> for ListPartitionReassignmentsResponse {
114 fn decode<B: Buf>(buf: &mut B, 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.throttle_time_ms = get_i32(buf)?;
125 }
126 if version >= 0 {
127 out.error_code = get_i16(buf)?;
128 }
129 if version >= 0 {
130 out.error_message = if flex {
131 get_compact_nullable_string_owned(buf)?
132 } else {
133 get_nullable_string_owned(buf)?
134 };
135 }
136 if version >= 0 {
137 out.topics = {
138 let n = get_array_len(buf, flex)?;
139 let mut v = Vec::with_capacity(n);
140 for _ in 0..n {
141 v.push(OngoingTopicReassignment::decode(buf, version)?);
142 }
143 v
144 };
145 }
146 if flex {
147 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
148 }
149 Ok(out)
150 }
151}
152#[cfg(test)]
153impl ListPartitionReassignmentsResponse {
154 #[must_use]
155 pub fn populated(version: i16) -> Self {
156 let mut m = Self::default();
157 if version >= 0 {
158 m.throttle_time_ms = 1i32;
159 }
160 if version >= 0 {
161 m.error_code = 1i16;
162 }
163 if version >= 0 {
164 m.error_message = Some("x".to_owned());
165 }
166 if version >= 0 {
167 m.topics = vec![OngoingTopicReassignment::populated(version)];
168 }
169 m
170 }
171}
172#[derive(Debug, Clone, PartialEq, Eq, Default)]
173pub struct OngoingTopicReassignment {
174 pub name: String,
175 pub partitions: Vec<OngoingPartitionReassignment>,
176 pub unknown_tagged_fields: UnknownTaggedFields,
177}
178impl Encode for OngoingTopicReassignment {
179 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
180 let flex = version >= 0;
181 if version >= 0 {
182 if flex {
183 put_compact_string(buf, &self.name)?;
184 } else {
185 put_string(buf, &self.name)?;
186 }
187 }
188 if version >= 0 {
189 {
190 put_array_len(buf, (self.partitions).len(), flex)?;
191 for it in &self.partitions {
192 it.encode(buf, version)?;
193 }
194 }
195 }
196 if flex {
197 let tagged = WriteTaggedFields::new();
198 tagged.write(buf, &self.unknown_tagged_fields)?;
199 }
200 Ok(())
201 }
202 fn encoded_len(&self, version: i16) -> usize {
203 let flex = version >= 0;
204 let mut n: usize = 0;
205 if version >= 0 {
206 n += if flex {
207 compact_string_len(&self.name)
208 } else {
209 string_len(&self.name)
210 };
211 }
212 if version >= 0 {
213 n += {
214 let prefix = array_len_prefix_len((self.partitions).len(), flex);
215 let body: usize = (self.partitions)
216 .iter()
217 .map(|it| it.encoded_len(version))
218 .sum();
219 prefix + body
220 };
221 }
222 if flex {
223 let known_pairs: Vec<(u32, usize)> = Vec::new();
224 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
225 }
226 n
227 }
228}
229impl Decode<'_> for OngoingTopicReassignment {
230 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
231 let flex = version >= 0;
232 let mut out = Self::default();
233 if version >= 0 {
234 out.name = if flex {
235 get_compact_string_owned(buf)?
236 } else {
237 get_string_owned(buf)?
238 };
239 }
240 if version >= 0 {
241 out.partitions = {
242 let n = get_array_len(buf, flex)?;
243 let mut v = Vec::with_capacity(n);
244 for _ in 0..n {
245 v.push(OngoingPartitionReassignment::decode(buf, version)?);
246 }
247 v
248 };
249 }
250 if flex {
251 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
252 }
253 Ok(out)
254 }
255}
256#[cfg(test)]
257impl OngoingTopicReassignment {
258 #[must_use]
259 pub fn populated(version: i16) -> Self {
260 let mut m = Self::default();
261 if version >= 0 {
262 m.name = "x".to_owned();
263 }
264 if version >= 0 {
265 m.partitions = vec![OngoingPartitionReassignment::populated(version)];
266 }
267 m
268 }
269}
270#[derive(Debug, Clone, PartialEq, Eq, Default)]
271pub struct OngoingPartitionReassignment {
272 pub partition_index: i32,
273 pub replicas: Vec<i32>,
274 pub adding_replicas: Vec<i32>,
275 pub removing_replicas: Vec<i32>,
276 pub unknown_tagged_fields: UnknownTaggedFields,
277}
278impl Encode for OngoingPartitionReassignment {
279 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
280 let flex = version >= 0;
281 if version >= 0 {
282 put_i32(buf, self.partition_index);
283 }
284 if version >= 0 {
285 {
286 put_array_len(buf, (self.replicas).len(), flex)?;
287 for it in &self.replicas {
288 put_i32(buf, *it);
289 }
290 }
291 }
292 if version >= 0 {
293 {
294 put_array_len(buf, (self.adding_replicas).len(), flex)?;
295 for it in &self.adding_replicas {
296 put_i32(buf, *it);
297 }
298 }
299 }
300 if version >= 0 {
301 {
302 put_array_len(buf, (self.removing_replicas).len(), flex)?;
303 for it in &self.removing_replicas {
304 put_i32(buf, *it);
305 }
306 }
307 }
308 if flex {
309 let tagged = WriteTaggedFields::new();
310 tagged.write(buf, &self.unknown_tagged_fields)?;
311 }
312 Ok(())
313 }
314 fn encoded_len(&self, version: i16) -> usize {
315 let flex = version >= 0;
316 let mut n: usize = 0;
317 if version >= 0 {
318 n += 4;
319 }
320 if version >= 0 {
321 n += {
322 let prefix = array_len_prefix_len((self.replicas).len(), flex);
323 let body: usize = (self.replicas).iter().map(|_| 4).sum();
324 prefix + body
325 };
326 }
327 if version >= 0 {
328 n += {
329 let prefix = array_len_prefix_len((self.adding_replicas).len(), flex);
330 let body: usize = (self.adding_replicas).iter().map(|_| 4).sum();
331 prefix + body
332 };
333 }
334 if version >= 0 {
335 n += {
336 let prefix = array_len_prefix_len((self.removing_replicas).len(), flex);
337 let body: usize = (self.removing_replicas).iter().map(|_| 4).sum();
338 prefix + body
339 };
340 }
341 if flex {
342 let known_pairs: Vec<(u32, usize)> = Vec::new();
343 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
344 }
345 n
346 }
347}
348impl Decode<'_> for OngoingPartitionReassignment {
349 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
350 let flex = version >= 0;
351 let mut out = Self::default();
352 if version >= 0 {
353 out.partition_index = get_i32(buf)?;
354 }
355 if version >= 0 {
356 out.replicas = {
357 let n = get_array_len(buf, flex)?;
358 let mut v = Vec::with_capacity(n);
359 for _ in 0..n {
360 v.push(get_i32(buf)?);
361 }
362 v
363 };
364 }
365 if version >= 0 {
366 out.adding_replicas = {
367 let n = get_array_len(buf, flex)?;
368 let mut v = Vec::with_capacity(n);
369 for _ in 0..n {
370 v.push(get_i32(buf)?);
371 }
372 v
373 };
374 }
375 if version >= 0 {
376 out.removing_replicas = {
377 let n = get_array_len(buf, flex)?;
378 let mut v = Vec::with_capacity(n);
379 for _ in 0..n {
380 v.push(get_i32(buf)?);
381 }
382 v
383 };
384 }
385 if flex {
386 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
387 }
388 Ok(out)
389 }
390}
391#[cfg(test)]
392impl OngoingPartitionReassignment {
393 #[must_use]
394 pub fn populated(version: i16) -> Self {
395 let mut m = Self::default();
396 if version >= 0 {
397 m.partition_index = 1i32;
398 }
399 if version >= 0 {
400 m.replicas = vec![1i32];
401 }
402 if version >= 0 {
403 m.adding_replicas = vec![1i32];
404 }
405 if version >= 0 {
406 m.removing_replicas = vec![1i32];
407 }
408 m
409 }
410}
411#[must_use]
414#[allow(unused_comparisons)]
415pub fn default_json(_version: i16) -> ::serde_json::Value {
416 let mut obj = ::serde_json::Map::new();
417 obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
418 obj.insert("errorCode".to_owned(), ::serde_json::json!(0));
419 obj.insert(
420 "errorMessage".to_owned(),
421 ::serde_json::Value::String(String::new()),
422 );
423 obj.insert("topics".to_owned(), ::serde_json::Value::Array(vec![]));
424 ::serde_json::Value::Object(obj)
425}