kafka_protocol/messages/
alter_partition_reassignments_response.rs

1//! AlterPartitionReassignmentsResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/AlterPartitionReassignmentsResponse.json).
4// WARNING: the items of this module are generated and should not be edited directly
5#![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/// Valid versions: 0-1
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct AlterPartitionReassignmentsResponse {
24    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
25    ///
26    /// Supported API versions: 0-1
27    pub throttle_time_ms: i32,
28
29    /// The option indicating whether changing the replication factor of any given partition as part of the request was allowed.
30    ///
31    /// Supported API versions: 1
32    pub allow_replication_factor_change: bool,
33
34    /// The top-level error code, or 0 if there was no error.
35    ///
36    /// Supported API versions: 0-1
37    pub error_code: i16,
38
39    /// The top-level error message, or null if there was no error.
40    ///
41    /// Supported API versions: 0-1
42    pub error_message: Option<StrBytes>,
43
44    /// The responses to topics to reassign.
45    ///
46    /// Supported API versions: 0-1
47    pub responses: Vec<ReassignableTopicResponse>,
48
49    /// Other tagged fields
50    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
51}
52
53impl AlterPartitionReassignmentsResponse {
54    /// Sets `throttle_time_ms` to the passed value.
55    ///
56    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
57    ///
58    /// Supported API versions: 0-1
59    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
60        self.throttle_time_ms = value;
61        self
62    }
63    /// Sets `allow_replication_factor_change` to the passed value.
64    ///
65    /// The option indicating whether changing the replication factor of any given partition as part of the request was allowed.
66    ///
67    /// Supported API versions: 1
68    pub fn with_allow_replication_factor_change(mut self, value: bool) -> Self {
69        self.allow_replication_factor_change = value;
70        self
71    }
72    /// Sets `error_code` to the passed value.
73    ///
74    /// The top-level error code, or 0 if there was no error.
75    ///
76    /// Supported API versions: 0-1
77    pub fn with_error_code(mut self, value: i16) -> Self {
78        self.error_code = value;
79        self
80    }
81    /// Sets `error_message` to the passed value.
82    ///
83    /// The top-level error message, or null if there was no error.
84    ///
85    /// Supported API versions: 0-1
86    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
87        self.error_message = value;
88        self
89    }
90    /// Sets `responses` to the passed value.
91    ///
92    /// The responses to topics to reassign.
93    ///
94    /// Supported API versions: 0-1
95    pub fn with_responses(mut self, value: Vec<ReassignableTopicResponse>) -> Self {
96        self.responses = value;
97        self
98    }
99    /// Sets unknown_tagged_fields to the passed value.
100    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
101        self.unknown_tagged_fields = value;
102        self
103    }
104    /// Inserts an entry into unknown_tagged_fields.
105    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/// Valid versions: 0-1
213#[non_exhaustive]
214#[derive(Debug, Clone, PartialEq)]
215pub struct ReassignablePartitionResponse {
216    /// The partition index.
217    ///
218    /// Supported API versions: 0-1
219    pub partition_index: i32,
220
221    /// The error code for this partition, or 0 if there was no error.
222    ///
223    /// Supported API versions: 0-1
224    pub error_code: i16,
225
226    /// The error message for this partition, or null if there was no error.
227    ///
228    /// Supported API versions: 0-1
229    pub error_message: Option<StrBytes>,
230
231    /// Other tagged fields
232    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
233}
234
235impl ReassignablePartitionResponse {
236    /// Sets `partition_index` to the passed value.
237    ///
238    /// The partition index.
239    ///
240    /// Supported API versions: 0-1
241    pub fn with_partition_index(mut self, value: i32) -> Self {
242        self.partition_index = value;
243        self
244    }
245    /// Sets `error_code` to the passed value.
246    ///
247    /// The error code for this partition, or 0 if there was no error.
248    ///
249    /// Supported API versions: 0-1
250    pub fn with_error_code(mut self, value: i16) -> Self {
251        self.error_code = value;
252        self
253    }
254    /// Sets `error_message` to the passed value.
255    ///
256    /// The error message for this partition, or null if there was no error.
257    ///
258    /// Supported API versions: 0-1
259    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
260        self.error_message = value;
261        self
262    }
263    /// Sets unknown_tagged_fields to the passed value.
264    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
265        self.unknown_tagged_fields = value;
266        self
267    }
268    /// Inserts an entry into unknown_tagged_fields.
269    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/// Valid versions: 0-1
358#[non_exhaustive]
359#[derive(Debug, Clone, PartialEq)]
360pub struct ReassignableTopicResponse {
361    /// The topic name.
362    ///
363    /// Supported API versions: 0-1
364    pub name: super::TopicName,
365
366    /// The responses to partitions to reassign.
367    ///
368    /// Supported API versions: 0-1
369    pub partitions: Vec<ReassignablePartitionResponse>,
370
371    /// Other tagged fields
372    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
373}
374
375impl ReassignableTopicResponse {
376    /// Sets `name` to the passed value.
377    ///
378    /// The topic name.
379    ///
380    /// Supported API versions: 0-1
381    pub fn with_name(mut self, value: super::TopicName) -> Self {
382        self.name = value;
383        self
384    }
385    /// Sets `partitions` to the passed value.
386    ///
387    /// The responses to partitions to reassign.
388    ///
389    /// Supported API versions: 0-1
390    pub fn with_partitions(mut self, value: Vec<ReassignablePartitionResponse>) -> Self {
391        self.partitions = value;
392        self
393    }
394    /// Sets unknown_tagged_fields to the passed value.
395    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
396        self.unknown_tagged_fields = value;
397        self
398    }
399    /// Inserts an entry into unknown_tagged_fields.
400    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}