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