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