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