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 ListPartitionReassignmentsResponse {
24 pub throttle_time_ms: i32,
28
29 pub error_code: i16,
33
34 pub error_message: Option<StrBytes>,
38
39 pub topics: Vec<OngoingTopicReassignment>,
43
44 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
46}
47
48impl ListPartitionReassignmentsResponse {
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_topics(mut self, value: Vec<OngoingTopicReassignment>) -> Self {
82 self.topics = 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 ListPartitionReassignmentsResponse {
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.topics)?;
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 += types::CompactArray(types::Struct { version }).compute_size(&self.topics)?;
122 let num_tagged_fields = self.unknown_tagged_fields.len();
123 if num_tagged_fields > std::u32::MAX as usize {
124 bail!(
125 "Too many tagged fields to encode ({} fields)",
126 num_tagged_fields
127 );
128 }
129 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
130
131 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
132 Ok(total_size)
133 }
134}
135
136#[cfg(feature = "client")]
137impl Decodable for ListPartitionReassignmentsResponse {
138 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
139 let throttle_time_ms = types::Int32.decode(buf)?;
140 let error_code = types::Int16.decode(buf)?;
141 let error_message = types::CompactString.decode(buf)?;
142 let topics = types::CompactArray(types::Struct { version }).decode(buf)?;
143 let mut unknown_tagged_fields = BTreeMap::new();
144 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
145 for _ in 0..num_tagged_fields {
146 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
147 let size: u32 = types::UnsignedVarInt.decode(buf)?;
148 let unknown_value = buf.try_get_bytes(size as usize)?;
149 unknown_tagged_fields.insert(tag as i32, unknown_value);
150 }
151 Ok(Self {
152 throttle_time_ms,
153 error_code,
154 error_message,
155 topics,
156 unknown_tagged_fields,
157 })
158 }
159}
160
161impl Default for ListPartitionReassignmentsResponse {
162 fn default() -> Self {
163 Self {
164 throttle_time_ms: 0,
165 error_code: 0,
166 error_message: Some(Default::default()),
167 topics: Default::default(),
168 unknown_tagged_fields: BTreeMap::new(),
169 }
170 }
171}
172
173impl Message for ListPartitionReassignmentsResponse {
174 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
175 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
176}
177
178#[non_exhaustive]
180#[derive(Debug, Clone, PartialEq)]
181pub struct OngoingPartitionReassignment {
182 pub partition_index: i32,
186
187 pub replicas: Vec<super::BrokerId>,
191
192 pub adding_replicas: Vec<super::BrokerId>,
196
197 pub removing_replicas: Vec<super::BrokerId>,
201
202 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
204}
205
206impl OngoingPartitionReassignment {
207 pub fn with_partition_index(mut self, value: i32) -> Self {
213 self.partition_index = value;
214 self
215 }
216 pub fn with_replicas(mut self, value: Vec<super::BrokerId>) -> Self {
222 self.replicas = value;
223 self
224 }
225 pub fn with_adding_replicas(mut self, value: Vec<super::BrokerId>) -> Self {
231 self.adding_replicas = value;
232 self
233 }
234 pub fn with_removing_replicas(mut self, value: Vec<super::BrokerId>) -> Self {
240 self.removing_replicas = value;
241 self
242 }
243 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
245 self.unknown_tagged_fields = value;
246 self
247 }
248 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
250 self.unknown_tagged_fields.insert(key, value);
251 self
252 }
253}
254
255#[cfg(feature = "broker")]
256impl Encodable for OngoingPartitionReassignment {
257 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
258 types::Int32.encode(buf, &self.partition_index)?;
259 types::CompactArray(types::Int32).encode(buf, &self.replicas)?;
260 types::CompactArray(types::Int32).encode(buf, &self.adding_replicas)?;
261 types::CompactArray(types::Int32).encode(buf, &self.removing_replicas)?;
262 let num_tagged_fields = self.unknown_tagged_fields.len();
263 if num_tagged_fields > std::u32::MAX as usize {
264 bail!(
265 "Too many tagged fields to encode ({} fields)",
266 num_tagged_fields
267 );
268 }
269 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
270
271 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
272 Ok(())
273 }
274 fn compute_size(&self, version: i16) -> Result<usize> {
275 let mut total_size = 0;
276 total_size += types::Int32.compute_size(&self.partition_index)?;
277 total_size += types::CompactArray(types::Int32).compute_size(&self.replicas)?;
278 total_size += types::CompactArray(types::Int32).compute_size(&self.adding_replicas)?;
279 total_size += types::CompactArray(types::Int32).compute_size(&self.removing_replicas)?;
280 let num_tagged_fields = self.unknown_tagged_fields.len();
281 if num_tagged_fields > std::u32::MAX as usize {
282 bail!(
283 "Too many tagged fields to encode ({} fields)",
284 num_tagged_fields
285 );
286 }
287 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
288
289 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
290 Ok(total_size)
291 }
292}
293
294#[cfg(feature = "client")]
295impl Decodable for OngoingPartitionReassignment {
296 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
297 let partition_index = types::Int32.decode(buf)?;
298 let replicas = types::CompactArray(types::Int32).decode(buf)?;
299 let adding_replicas = types::CompactArray(types::Int32).decode(buf)?;
300 let removing_replicas = types::CompactArray(types::Int32).decode(buf)?;
301 let mut unknown_tagged_fields = BTreeMap::new();
302 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
303 for _ in 0..num_tagged_fields {
304 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
305 let size: u32 = types::UnsignedVarInt.decode(buf)?;
306 let unknown_value = buf.try_get_bytes(size as usize)?;
307 unknown_tagged_fields.insert(tag as i32, unknown_value);
308 }
309 Ok(Self {
310 partition_index,
311 replicas,
312 adding_replicas,
313 removing_replicas,
314 unknown_tagged_fields,
315 })
316 }
317}
318
319impl Default for OngoingPartitionReassignment {
320 fn default() -> Self {
321 Self {
322 partition_index: 0,
323 replicas: Default::default(),
324 adding_replicas: Default::default(),
325 removing_replicas: Default::default(),
326 unknown_tagged_fields: BTreeMap::new(),
327 }
328 }
329}
330
331impl Message for OngoingPartitionReassignment {
332 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
333 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
334}
335
336#[non_exhaustive]
338#[derive(Debug, Clone, PartialEq)]
339pub struct OngoingTopicReassignment {
340 pub name: super::TopicName,
344
345 pub partitions: Vec<OngoingPartitionReassignment>,
349
350 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
352}
353
354impl OngoingTopicReassignment {
355 pub fn with_name(mut self, value: super::TopicName) -> Self {
361 self.name = value;
362 self
363 }
364 pub fn with_partitions(mut self, value: Vec<OngoingPartitionReassignment>) -> Self {
370 self.partitions = value;
371 self
372 }
373 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
375 self.unknown_tagged_fields = value;
376 self
377 }
378 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
380 self.unknown_tagged_fields.insert(key, value);
381 self
382 }
383}
384
385#[cfg(feature = "broker")]
386impl Encodable for OngoingTopicReassignment {
387 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
388 types::CompactString.encode(buf, &self.name)?;
389 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
390 let num_tagged_fields = self.unknown_tagged_fields.len();
391 if num_tagged_fields > std::u32::MAX as usize {
392 bail!(
393 "Too many tagged fields to encode ({} fields)",
394 num_tagged_fields
395 );
396 }
397 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
398
399 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
400 Ok(())
401 }
402 fn compute_size(&self, version: i16) -> Result<usize> {
403 let mut total_size = 0;
404 total_size += types::CompactString.compute_size(&self.name)?;
405 total_size +=
406 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
407 let num_tagged_fields = self.unknown_tagged_fields.len();
408 if num_tagged_fields > std::u32::MAX as usize {
409 bail!(
410 "Too many tagged fields to encode ({} fields)",
411 num_tagged_fields
412 );
413 }
414 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
415
416 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
417 Ok(total_size)
418 }
419}
420
421#[cfg(feature = "client")]
422impl Decodable for OngoingTopicReassignment {
423 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
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 OngoingTopicReassignment {
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 OngoingTopicReassignment {
453 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
454 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
455}
456
457impl HeaderVersion for ListPartitionReassignmentsResponse {
458 fn header_version(version: i16) -> i16 {
459 1
460 }
461}