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 types::Int32.encode(buf, &self.throttle_time_ms)?;
101 types::Int16.encode(buf, &self.error_code)?;
102 types::CompactString.encode(buf, &self.error_message)?;
103 types::CompactArray(types::Struct { version }).encode(buf, &self.responses)?;
104 let num_tagged_fields = self.unknown_tagged_fields.len();
105 if num_tagged_fields > std::u32::MAX as usize {
106 bail!(
107 "Too many tagged fields to encode ({} fields)",
108 num_tagged_fields
109 );
110 }
111 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
112
113 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
114 Ok(())
115 }
116 fn compute_size(&self, version: i16) -> Result<usize> {
117 let mut total_size = 0;
118 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
119 total_size += types::Int16.compute_size(&self.error_code)?;
120 total_size += types::CompactString.compute_size(&self.error_message)?;
121 total_size +=
122 types::CompactArray(types::Struct { version }).compute_size(&self.responses)?;
123 let num_tagged_fields = self.unknown_tagged_fields.len();
124 if num_tagged_fields > std::u32::MAX as usize {
125 bail!(
126 "Too many tagged fields to encode ({} fields)",
127 num_tagged_fields
128 );
129 }
130 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
131
132 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
133 Ok(total_size)
134 }
135}
136
137#[cfg(feature = "client")]
138impl Decodable for AlterPartitionReassignmentsResponse {
139 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
140 let throttle_time_ms = types::Int32.decode(buf)?;
141 let error_code = types::Int16.decode(buf)?;
142 let error_message = types::CompactString.decode(buf)?;
143 let responses = types::CompactArray(types::Struct { version }).decode(buf)?;
144 let mut unknown_tagged_fields = BTreeMap::new();
145 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
146 for _ in 0..num_tagged_fields {
147 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
148 let size: u32 = types::UnsignedVarInt.decode(buf)?;
149 let unknown_value = buf.try_get_bytes(size as usize)?;
150 unknown_tagged_fields.insert(tag as i32, unknown_value);
151 }
152 Ok(Self {
153 throttle_time_ms,
154 error_code,
155 error_message,
156 responses,
157 unknown_tagged_fields,
158 })
159 }
160}
161
162impl Default for AlterPartitionReassignmentsResponse {
163 fn default() -> Self {
164 Self {
165 throttle_time_ms: 0,
166 error_code: 0,
167 error_message: Some(Default::default()),
168 responses: Default::default(),
169 unknown_tagged_fields: BTreeMap::new(),
170 }
171 }
172}
173
174impl Message for AlterPartitionReassignmentsResponse {
175 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
176 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
177}
178
179#[non_exhaustive]
181#[derive(Debug, Clone, PartialEq)]
182pub struct ReassignablePartitionResponse {
183 pub partition_index: i32,
187
188 pub error_code: i16,
192
193 pub error_message: Option<StrBytes>,
197
198 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
200}
201
202impl ReassignablePartitionResponse {
203 pub fn with_partition_index(mut self, value: i32) -> Self {
209 self.partition_index = value;
210 self
211 }
212 pub fn with_error_code(mut self, value: i16) -> Self {
218 self.error_code = value;
219 self
220 }
221 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
227 self.error_message = value;
228 self
229 }
230 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
232 self.unknown_tagged_fields = value;
233 self
234 }
235 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
237 self.unknown_tagged_fields.insert(key, value);
238 self
239 }
240}
241
242#[cfg(feature = "broker")]
243impl Encodable for ReassignablePartitionResponse {
244 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
245 types::Int32.encode(buf, &self.partition_index)?;
246 types::Int16.encode(buf, &self.error_code)?;
247 types::CompactString.encode(buf, &self.error_message)?;
248 let num_tagged_fields = self.unknown_tagged_fields.len();
249 if num_tagged_fields > std::u32::MAX as usize {
250 bail!(
251 "Too many tagged fields to encode ({} fields)",
252 num_tagged_fields
253 );
254 }
255 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
256
257 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
258 Ok(())
259 }
260 fn compute_size(&self, version: i16) -> Result<usize> {
261 let mut total_size = 0;
262 total_size += types::Int32.compute_size(&self.partition_index)?;
263 total_size += types::Int16.compute_size(&self.error_code)?;
264 total_size += types::CompactString.compute_size(&self.error_message)?;
265 let num_tagged_fields = self.unknown_tagged_fields.len();
266 if num_tagged_fields > std::u32::MAX as usize {
267 bail!(
268 "Too many tagged fields to encode ({} fields)",
269 num_tagged_fields
270 );
271 }
272 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
273
274 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
275 Ok(total_size)
276 }
277}
278
279#[cfg(feature = "client")]
280impl Decodable for ReassignablePartitionResponse {
281 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
282 let partition_index = types::Int32.decode(buf)?;
283 let error_code = types::Int16.decode(buf)?;
284 let error_message = types::CompactString.decode(buf)?;
285 let mut unknown_tagged_fields = BTreeMap::new();
286 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
287 for _ in 0..num_tagged_fields {
288 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
289 let size: u32 = types::UnsignedVarInt.decode(buf)?;
290 let unknown_value = buf.try_get_bytes(size as usize)?;
291 unknown_tagged_fields.insert(tag as i32, unknown_value);
292 }
293 Ok(Self {
294 partition_index,
295 error_code,
296 error_message,
297 unknown_tagged_fields,
298 })
299 }
300}
301
302impl Default for ReassignablePartitionResponse {
303 fn default() -> Self {
304 Self {
305 partition_index: 0,
306 error_code: 0,
307 error_message: Some(Default::default()),
308 unknown_tagged_fields: BTreeMap::new(),
309 }
310 }
311}
312
313impl Message for ReassignablePartitionResponse {
314 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
315 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
316}
317
318#[non_exhaustive]
320#[derive(Debug, Clone, PartialEq)]
321pub struct ReassignableTopicResponse {
322 pub name: super::TopicName,
326
327 pub partitions: Vec<ReassignablePartitionResponse>,
331
332 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
334}
335
336impl ReassignableTopicResponse {
337 pub fn with_name(mut self, value: super::TopicName) -> Self {
343 self.name = value;
344 self
345 }
346 pub fn with_partitions(mut self, value: Vec<ReassignablePartitionResponse>) -> Self {
352 self.partitions = value;
353 self
354 }
355 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
357 self.unknown_tagged_fields = value;
358 self
359 }
360 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
362 self.unknown_tagged_fields.insert(key, value);
363 self
364 }
365}
366
367#[cfg(feature = "broker")]
368impl Encodable for ReassignableTopicResponse {
369 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
370 types::CompactString.encode(buf, &self.name)?;
371 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
372 let num_tagged_fields = self.unknown_tagged_fields.len();
373 if num_tagged_fields > std::u32::MAX as usize {
374 bail!(
375 "Too many tagged fields to encode ({} fields)",
376 num_tagged_fields
377 );
378 }
379 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
380
381 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
382 Ok(())
383 }
384 fn compute_size(&self, version: i16) -> Result<usize> {
385 let mut total_size = 0;
386 total_size += types::CompactString.compute_size(&self.name)?;
387 total_size +=
388 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
389 let num_tagged_fields = self.unknown_tagged_fields.len();
390 if num_tagged_fields > std::u32::MAX as usize {
391 bail!(
392 "Too many tagged fields to encode ({} fields)",
393 num_tagged_fields
394 );
395 }
396 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
397
398 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
399 Ok(total_size)
400 }
401}
402
403#[cfg(feature = "client")]
404impl Decodable for ReassignableTopicResponse {
405 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
406 let name = types::CompactString.decode(buf)?;
407 let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
408 let mut unknown_tagged_fields = BTreeMap::new();
409 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
410 for _ in 0..num_tagged_fields {
411 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
412 let size: u32 = types::UnsignedVarInt.decode(buf)?;
413 let unknown_value = buf.try_get_bytes(size as usize)?;
414 unknown_tagged_fields.insert(tag as i32, unknown_value);
415 }
416 Ok(Self {
417 name,
418 partitions,
419 unknown_tagged_fields,
420 })
421 }
422}
423
424impl Default for ReassignableTopicResponse {
425 fn default() -> Self {
426 Self {
427 name: Default::default(),
428 partitions: Default::default(),
429 unknown_tagged_fields: BTreeMap::new(),
430 }
431 }
432}
433
434impl Message for ReassignableTopicResponse {
435 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
436 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
437}
438
439impl HeaderVersion for AlterPartitionReassignmentsResponse {
440 fn header_version(version: i16) -> i16 {
441 1
442 }
443}