1#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15 buf::{ByteBuf, ByteBufMut},
16 compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17 Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct AlterPartitionReassignmentsResponse {
24 pub throttle_time_ms: i32,
28
29 pub allow_replication_factor_change: bool,
33
34 pub error_code: i16,
38
39 pub error_message: Option<StrBytes>,
43
44 pub responses: Vec<ReassignableTopicResponse>,
48
49 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
51}
52
53impl AlterPartitionReassignmentsResponse {
54 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
60 self.throttle_time_ms = value;
61 self
62 }
63 pub fn with_allow_replication_factor_change(mut self, value: bool) -> Self {
69 self.allow_replication_factor_change = value;
70 self
71 }
72 pub fn with_error_code(mut self, value: i16) -> Self {
78 self.error_code = value;
79 self
80 }
81 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
87 self.error_message = value;
88 self
89 }
90 pub fn with_responses(mut self, value: Vec<ReassignableTopicResponse>) -> Self {
96 self.responses = value;
97 self
98 }
99 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
101 self.unknown_tagged_fields = value;
102 self
103 }
104 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
106 self.unknown_tagged_fields.insert(key, value);
107 self
108 }
109}
110
111#[cfg(feature = "broker")]
112impl Encodable for AlterPartitionReassignmentsResponse {
113 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
114 if version < 0 || version > 1 {
115 bail!("specified version not supported by this message type");
116 }
117 types::Int32.encode(buf, &self.throttle_time_ms)?;
118 if version >= 1 {
119 types::Boolean.encode(buf, &self.allow_replication_factor_change)?;
120 }
121 types::Int16.encode(buf, &self.error_code)?;
122 types::CompactString.encode(buf, &self.error_message)?;
123 types::CompactArray(types::Struct { version }).encode(buf, &self.responses)?;
124 let num_tagged_fields = self.unknown_tagged_fields.len();
125 if num_tagged_fields > std::u32::MAX as usize {
126 bail!(
127 "Too many tagged fields to encode ({} fields)",
128 num_tagged_fields
129 );
130 }
131 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
132
133 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
134 Ok(())
135 }
136 fn compute_size(&self, version: i16) -> Result<usize> {
137 let mut total_size = 0;
138 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
139 if version >= 1 {
140 total_size += types::Boolean.compute_size(&self.allow_replication_factor_change)?;
141 }
142 total_size += types::Int16.compute_size(&self.error_code)?;
143 total_size += types::CompactString.compute_size(&self.error_message)?;
144 total_size +=
145 types::CompactArray(types::Struct { version }).compute_size(&self.responses)?;
146 let num_tagged_fields = self.unknown_tagged_fields.len();
147 if num_tagged_fields > std::u32::MAX as usize {
148 bail!(
149 "Too many tagged fields to encode ({} fields)",
150 num_tagged_fields
151 );
152 }
153 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
154
155 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
156 Ok(total_size)
157 }
158}
159
160#[cfg(feature = "client")]
161impl Decodable for AlterPartitionReassignmentsResponse {
162 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
163 if version < 0 || version > 1 {
164 bail!("specified version not supported by this message type");
165 }
166 let throttle_time_ms = types::Int32.decode(buf)?;
167 let allow_replication_factor_change = if version >= 1 {
168 types::Boolean.decode(buf)?
169 } else {
170 true
171 };
172 let error_code = types::Int16.decode(buf)?;
173 let error_message = types::CompactString.decode(buf)?;
174 let responses = types::CompactArray(types::Struct { version }).decode(buf)?;
175 let mut unknown_tagged_fields = BTreeMap::new();
176 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
177 for _ in 0..num_tagged_fields {
178 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
179 let size: u32 = types::UnsignedVarInt.decode(buf)?;
180 let unknown_value = buf.try_get_bytes(size as usize)?;
181 unknown_tagged_fields.insert(tag as i32, unknown_value);
182 }
183 Ok(Self {
184 throttle_time_ms,
185 allow_replication_factor_change,
186 error_code,
187 error_message,
188 responses,
189 unknown_tagged_fields,
190 })
191 }
192}
193
194impl Default for AlterPartitionReassignmentsResponse {
195 fn default() -> Self {
196 Self {
197 throttle_time_ms: 0,
198 allow_replication_factor_change: true,
199 error_code: 0,
200 error_message: Some(Default::default()),
201 responses: Default::default(),
202 unknown_tagged_fields: BTreeMap::new(),
203 }
204 }
205}
206
207impl Message for AlterPartitionReassignmentsResponse {
208 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
209 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
210}
211
212#[non_exhaustive]
214#[derive(Debug, Clone, PartialEq)]
215pub struct ReassignablePartitionResponse {
216 pub partition_index: i32,
220
221 pub error_code: i16,
225
226 pub error_message: Option<StrBytes>,
230
231 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
233}
234
235impl ReassignablePartitionResponse {
236 pub fn with_partition_index(mut self, value: i32) -> Self {
242 self.partition_index = value;
243 self
244 }
245 pub fn with_error_code(mut self, value: i16) -> Self {
251 self.error_code = value;
252 self
253 }
254 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
260 self.error_message = value;
261 self
262 }
263 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
265 self.unknown_tagged_fields = value;
266 self
267 }
268 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
270 self.unknown_tagged_fields.insert(key, value);
271 self
272 }
273}
274
275#[cfg(feature = "broker")]
276impl Encodable for ReassignablePartitionResponse {
277 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
278 if version < 0 || version > 1 {
279 bail!("specified version not supported by this message type");
280 }
281 types::Int32.encode(buf, &self.partition_index)?;
282 types::Int16.encode(buf, &self.error_code)?;
283 types::CompactString.encode(buf, &self.error_message)?;
284 let num_tagged_fields = self.unknown_tagged_fields.len();
285 if num_tagged_fields > std::u32::MAX as usize {
286 bail!(
287 "Too many tagged fields to encode ({} fields)",
288 num_tagged_fields
289 );
290 }
291 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
292
293 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
294 Ok(())
295 }
296 fn compute_size(&self, version: i16) -> Result<usize> {
297 let mut total_size = 0;
298 total_size += types::Int32.compute_size(&self.partition_index)?;
299 total_size += types::Int16.compute_size(&self.error_code)?;
300 total_size += types::CompactString.compute_size(&self.error_message)?;
301 let num_tagged_fields = self.unknown_tagged_fields.len();
302 if num_tagged_fields > std::u32::MAX as usize {
303 bail!(
304 "Too many tagged fields to encode ({} fields)",
305 num_tagged_fields
306 );
307 }
308 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
309
310 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
311 Ok(total_size)
312 }
313}
314
315#[cfg(feature = "client")]
316impl Decodable for ReassignablePartitionResponse {
317 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
318 if version < 0 || version > 1 {
319 bail!("specified version not supported by this message type");
320 }
321 let partition_index = types::Int32.decode(buf)?;
322 let error_code = types::Int16.decode(buf)?;
323 let error_message = types::CompactString.decode(buf)?;
324 let mut unknown_tagged_fields = BTreeMap::new();
325 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
326 for _ in 0..num_tagged_fields {
327 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
328 let size: u32 = types::UnsignedVarInt.decode(buf)?;
329 let unknown_value = buf.try_get_bytes(size as usize)?;
330 unknown_tagged_fields.insert(tag as i32, unknown_value);
331 }
332 Ok(Self {
333 partition_index,
334 error_code,
335 error_message,
336 unknown_tagged_fields,
337 })
338 }
339}
340
341impl Default for ReassignablePartitionResponse {
342 fn default() -> Self {
343 Self {
344 partition_index: 0,
345 error_code: 0,
346 error_message: Some(Default::default()),
347 unknown_tagged_fields: BTreeMap::new(),
348 }
349 }
350}
351
352impl Message for ReassignablePartitionResponse {
353 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
354 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
355}
356
357#[non_exhaustive]
359#[derive(Debug, Clone, PartialEq)]
360pub struct ReassignableTopicResponse {
361 pub name: super::TopicName,
365
366 pub partitions: Vec<ReassignablePartitionResponse>,
370
371 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
373}
374
375impl ReassignableTopicResponse {
376 pub fn with_name(mut self, value: super::TopicName) -> Self {
382 self.name = value;
383 self
384 }
385 pub fn with_partitions(mut self, value: Vec<ReassignablePartitionResponse>) -> Self {
391 self.partitions = value;
392 self
393 }
394 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
396 self.unknown_tagged_fields = value;
397 self
398 }
399 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
401 self.unknown_tagged_fields.insert(key, value);
402 self
403 }
404}
405
406#[cfg(feature = "broker")]
407impl Encodable for ReassignableTopicResponse {
408 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
409 if version < 0 || version > 1 {
410 bail!("specified version not supported by this message type");
411 }
412 types::CompactString.encode(buf, &self.name)?;
413 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
414 let num_tagged_fields = self.unknown_tagged_fields.len();
415 if num_tagged_fields > std::u32::MAX as usize {
416 bail!(
417 "Too many tagged fields to encode ({} fields)",
418 num_tagged_fields
419 );
420 }
421 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
422
423 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
424 Ok(())
425 }
426 fn compute_size(&self, version: i16) -> Result<usize> {
427 let mut total_size = 0;
428 total_size += types::CompactString.compute_size(&self.name)?;
429 total_size +=
430 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
431 let num_tagged_fields = self.unknown_tagged_fields.len();
432 if num_tagged_fields > std::u32::MAX as usize {
433 bail!(
434 "Too many tagged fields to encode ({} fields)",
435 num_tagged_fields
436 );
437 }
438 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
439
440 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
441 Ok(total_size)
442 }
443}
444
445#[cfg(feature = "client")]
446impl Decodable for ReassignableTopicResponse {
447 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
448 if version < 0 || version > 1 {
449 bail!("specified version not supported by this message type");
450 }
451 let name = types::CompactString.decode(buf)?;
452 let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
453 let mut unknown_tagged_fields = BTreeMap::new();
454 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
455 for _ in 0..num_tagged_fields {
456 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
457 let size: u32 = types::UnsignedVarInt.decode(buf)?;
458 let unknown_value = buf.try_get_bytes(size as usize)?;
459 unknown_tagged_fields.insert(tag as i32, unknown_value);
460 }
461 Ok(Self {
462 name,
463 partitions,
464 unknown_tagged_fields,
465 })
466 }
467}
468
469impl Default for ReassignableTopicResponse {
470 fn default() -> Self {
471 Self {
472 name: Default::default(),
473 partitions: Default::default(),
474 unknown_tagged_fields: BTreeMap::new(),
475 }
476 }
477}
478
479impl Message for ReassignableTopicResponse {
480 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
481 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
482}
483
484impl HeaderVersion for AlterPartitionReassignmentsResponse {
485 fn header_version(version: i16) -> i16 {
486 1
487 }
488}