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 error_code: i16,
33
34 pub error_message: Option<StrBytes>,
38
39 pub responses: Vec<ReassignableTopicResponse>,
43
44 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
46}
47
48impl AlterPartitionReassignmentsResponse {
49 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
55 self.throttle_time_ms = value;
56 self
57 }
58 pub fn with_error_code(mut self, value: i16) -> Self {
64 self.error_code = value;
65 self
66 }
67 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
73 self.error_message = value;
74 self
75 }
76 pub fn with_responses(mut self, value: Vec<ReassignableTopicResponse>) -> Self {
82 self.responses = value;
83 self
84 }
85 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
87 self.unknown_tagged_fields = value;
88 self
89 }
90 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
92 self.unknown_tagged_fields.insert(key, value);
93 self
94 }
95}
96
97#[cfg(feature = "broker")]
98impl Encodable for AlterPartitionReassignmentsResponse {
99 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
100 if version != 0 {
101 bail!("specified version not supported by this message type");
102 }
103 types::Int32.encode(buf, &self.throttle_time_ms)?;
104 types::Int16.encode(buf, &self.error_code)?;
105 types::CompactString.encode(buf, &self.error_message)?;
106 types::CompactArray(types::Struct { version }).encode(buf, &self.responses)?;
107 let num_tagged_fields = self.unknown_tagged_fields.len();
108 if num_tagged_fields > std::u32::MAX as usize {
109 bail!(
110 "Too many tagged fields to encode ({} fields)",
111 num_tagged_fields
112 );
113 }
114 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
115
116 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
117 Ok(())
118 }
119 fn compute_size(&self, version: i16) -> Result<usize> {
120 let mut total_size = 0;
121 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
122 total_size += types::Int16.compute_size(&self.error_code)?;
123 total_size += types::CompactString.compute_size(&self.error_message)?;
124 total_size +=
125 types::CompactArray(types::Struct { version }).compute_size(&self.responses)?;
126 let num_tagged_fields = self.unknown_tagged_fields.len();
127 if num_tagged_fields > std::u32::MAX as usize {
128 bail!(
129 "Too many tagged fields to encode ({} fields)",
130 num_tagged_fields
131 );
132 }
133 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
134
135 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
136 Ok(total_size)
137 }
138}
139
140#[cfg(feature = "client")]
141impl Decodable for AlterPartitionReassignmentsResponse {
142 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
143 if version != 0 {
144 bail!("specified version not supported by this message type");
145 }
146 let throttle_time_ms = types::Int32.decode(buf)?;
147 let error_code = types::Int16.decode(buf)?;
148 let error_message = types::CompactString.decode(buf)?;
149 let responses = types::CompactArray(types::Struct { version }).decode(buf)?;
150 let mut unknown_tagged_fields = BTreeMap::new();
151 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
152 for _ in 0..num_tagged_fields {
153 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
154 let size: u32 = types::UnsignedVarInt.decode(buf)?;
155 let unknown_value = buf.try_get_bytes(size as usize)?;
156 unknown_tagged_fields.insert(tag as i32, unknown_value);
157 }
158 Ok(Self {
159 throttle_time_ms,
160 error_code,
161 error_message,
162 responses,
163 unknown_tagged_fields,
164 })
165 }
166}
167
168impl Default for AlterPartitionReassignmentsResponse {
169 fn default() -> Self {
170 Self {
171 throttle_time_ms: 0,
172 error_code: 0,
173 error_message: Some(Default::default()),
174 responses: Default::default(),
175 unknown_tagged_fields: BTreeMap::new(),
176 }
177 }
178}
179
180impl Message for AlterPartitionReassignmentsResponse {
181 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
182 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
183}
184
185#[non_exhaustive]
187#[derive(Debug, Clone, PartialEq)]
188pub struct ReassignablePartitionResponse {
189 pub partition_index: i32,
193
194 pub error_code: i16,
198
199 pub error_message: Option<StrBytes>,
203
204 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
206}
207
208impl ReassignablePartitionResponse {
209 pub fn with_partition_index(mut self, value: i32) -> Self {
215 self.partition_index = value;
216 self
217 }
218 pub fn with_error_code(mut self, value: i16) -> Self {
224 self.error_code = value;
225 self
226 }
227 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
233 self.error_message = value;
234 self
235 }
236 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
238 self.unknown_tagged_fields = value;
239 self
240 }
241 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
243 self.unknown_tagged_fields.insert(key, value);
244 self
245 }
246}
247
248#[cfg(feature = "broker")]
249impl Encodable for ReassignablePartitionResponse {
250 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
251 if version != 0 {
252 bail!("specified version not supported by this message type");
253 }
254 types::Int32.encode(buf, &self.partition_index)?;
255 types::Int16.encode(buf, &self.error_code)?;
256 types::CompactString.encode(buf, &self.error_message)?;
257 let num_tagged_fields = self.unknown_tagged_fields.len();
258 if num_tagged_fields > std::u32::MAX as usize {
259 bail!(
260 "Too many tagged fields to encode ({} fields)",
261 num_tagged_fields
262 );
263 }
264 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
265
266 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
267 Ok(())
268 }
269 fn compute_size(&self, version: i16) -> Result<usize> {
270 let mut total_size = 0;
271 total_size += types::Int32.compute_size(&self.partition_index)?;
272 total_size += types::Int16.compute_size(&self.error_code)?;
273 total_size += types::CompactString.compute_size(&self.error_message)?;
274 let num_tagged_fields = self.unknown_tagged_fields.len();
275 if num_tagged_fields > std::u32::MAX as usize {
276 bail!(
277 "Too many tagged fields to encode ({} fields)",
278 num_tagged_fields
279 );
280 }
281 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
282
283 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
284 Ok(total_size)
285 }
286}
287
288#[cfg(feature = "client")]
289impl Decodable for ReassignablePartitionResponse {
290 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
291 if version != 0 {
292 bail!("specified version not supported by this message type");
293 }
294 let partition_index = types::Int32.decode(buf)?;
295 let error_code = types::Int16.decode(buf)?;
296 let error_message = types::CompactString.decode(buf)?;
297 let mut unknown_tagged_fields = BTreeMap::new();
298 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
299 for _ in 0..num_tagged_fields {
300 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
301 let size: u32 = types::UnsignedVarInt.decode(buf)?;
302 let unknown_value = buf.try_get_bytes(size as usize)?;
303 unknown_tagged_fields.insert(tag as i32, unknown_value);
304 }
305 Ok(Self {
306 partition_index,
307 error_code,
308 error_message,
309 unknown_tagged_fields,
310 })
311 }
312}
313
314impl Default for ReassignablePartitionResponse {
315 fn default() -> Self {
316 Self {
317 partition_index: 0,
318 error_code: 0,
319 error_message: Some(Default::default()),
320 unknown_tagged_fields: BTreeMap::new(),
321 }
322 }
323}
324
325impl Message for ReassignablePartitionResponse {
326 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
327 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
328}
329
330#[non_exhaustive]
332#[derive(Debug, Clone, PartialEq)]
333pub struct ReassignableTopicResponse {
334 pub name: super::TopicName,
338
339 pub partitions: Vec<ReassignablePartitionResponse>,
343
344 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
346}
347
348impl ReassignableTopicResponse {
349 pub fn with_name(mut self, value: super::TopicName) -> Self {
355 self.name = value;
356 self
357 }
358 pub fn with_partitions(mut self, value: Vec<ReassignablePartitionResponse>) -> Self {
364 self.partitions = value;
365 self
366 }
367 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
369 self.unknown_tagged_fields = value;
370 self
371 }
372 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
374 self.unknown_tagged_fields.insert(key, value);
375 self
376 }
377}
378
379#[cfg(feature = "broker")]
380impl Encodable for ReassignableTopicResponse {
381 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
382 if version != 0 {
383 bail!("specified version not supported by this message type");
384 }
385 types::CompactString.encode(buf, &self.name)?;
386 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
387 let num_tagged_fields = self.unknown_tagged_fields.len();
388 if num_tagged_fields > std::u32::MAX as usize {
389 bail!(
390 "Too many tagged fields to encode ({} fields)",
391 num_tagged_fields
392 );
393 }
394 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
395
396 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
397 Ok(())
398 }
399 fn compute_size(&self, version: i16) -> Result<usize> {
400 let mut total_size = 0;
401 total_size += types::CompactString.compute_size(&self.name)?;
402 total_size +=
403 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
404 let num_tagged_fields = self.unknown_tagged_fields.len();
405 if num_tagged_fields > std::u32::MAX as usize {
406 bail!(
407 "Too many tagged fields to encode ({} fields)",
408 num_tagged_fields
409 );
410 }
411 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
412
413 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
414 Ok(total_size)
415 }
416}
417
418#[cfg(feature = "client")]
419impl Decodable for ReassignableTopicResponse {
420 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
421 if version != 0 {
422 bail!("specified version not supported by this message type");
423 }
424 let name = types::CompactString.decode(buf)?;
425 let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
426 let mut unknown_tagged_fields = BTreeMap::new();
427 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
428 for _ in 0..num_tagged_fields {
429 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
430 let size: u32 = types::UnsignedVarInt.decode(buf)?;
431 let unknown_value = buf.try_get_bytes(size as usize)?;
432 unknown_tagged_fields.insert(tag as i32, unknown_value);
433 }
434 Ok(Self {
435 name,
436 partitions,
437 unknown_tagged_fields,
438 })
439 }
440}
441
442impl Default for ReassignableTopicResponse {
443 fn default() -> Self {
444 Self {
445 name: Default::default(),
446 partitions: Default::default(),
447 unknown_tagged_fields: BTreeMap::new(),
448 }
449 }
450}
451
452impl Message for ReassignableTopicResponse {
453 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
454 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
455}
456
457impl HeaderVersion for AlterPartitionReassignmentsResponse {
458 fn header_version(version: i16) -> i16 {
459 1
460 }
461}