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