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