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
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
27    pub throttle_time_ms: i32,
28
29    /// The top-level error code, or 0 if there was no error.
30    ///
31    /// Supported API versions: 0
32    pub error_code: i16,
33
34    /// The top-level error message, or null if there was no error.
35    ///
36    /// Supported API versions: 0
37    pub error_message: Option<StrBytes>,
38
39    /// The responses to topics to reassign.
40    ///
41    /// Supported API versions: 0
42    pub responses: Vec<ReassignableTopicResponse>,
43
44    /// Other tagged fields
45    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
46}
47
48impl AlterPartitionReassignmentsResponse {
49    /// Sets `throttle_time_ms` to the passed value.
50    ///
51    /// 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.
52    ///
53    /// Supported API versions: 0
54    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
55        self.throttle_time_ms = value;
56        self
57    }
58    /// Sets `error_code` to the passed value.
59    ///
60    /// The top-level error code, or 0 if there was no error.
61    ///
62    /// Supported API versions: 0
63    pub fn with_error_code(mut self, value: i16) -> Self {
64        self.error_code = value;
65        self
66    }
67    /// Sets `error_message` to the passed value.
68    ///
69    /// The top-level error message, or null if there was no error.
70    ///
71    /// Supported API versions: 0
72    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
73        self.error_message = value;
74        self
75    }
76    /// Sets `responses` to the passed value.
77    ///
78    /// The responses to topics to reassign.
79    ///
80    /// Supported API versions: 0
81    pub fn with_responses(mut self, value: Vec<ReassignableTopicResponse>) -> Self {
82        self.responses = value;
83        self
84    }
85    /// Sets unknown_tagged_fields to the passed value.
86    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
87        self.unknown_tagged_fields = value;
88        self
89    }
90    /// Inserts an entry into unknown_tagged_fields.
91    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/// Valid versions: 0
186#[non_exhaustive]
187#[derive(Debug, Clone, PartialEq)]
188pub struct ReassignablePartitionResponse {
189    /// The partition index.
190    ///
191    /// Supported API versions: 0
192    pub partition_index: i32,
193
194    /// The error code for this partition, or 0 if there was no error.
195    ///
196    /// Supported API versions: 0
197    pub error_code: i16,
198
199    /// The error message for this partition, or null if there was no error.
200    ///
201    /// Supported API versions: 0
202    pub error_message: Option<StrBytes>,
203
204    /// Other tagged fields
205    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
206}
207
208impl ReassignablePartitionResponse {
209    /// Sets `partition_index` to the passed value.
210    ///
211    /// The partition index.
212    ///
213    /// Supported API versions: 0
214    pub fn with_partition_index(mut self, value: i32) -> Self {
215        self.partition_index = value;
216        self
217    }
218    /// Sets `error_code` to the passed value.
219    ///
220    /// The error code for this partition, or 0 if there was no error.
221    ///
222    /// Supported API versions: 0
223    pub fn with_error_code(mut self, value: i16) -> Self {
224        self.error_code = value;
225        self
226    }
227    /// Sets `error_message` to the passed value.
228    ///
229    /// The error message for this partition, or null if there was no error.
230    ///
231    /// Supported API versions: 0
232    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
233        self.error_message = value;
234        self
235    }
236    /// Sets unknown_tagged_fields to the passed value.
237    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
238        self.unknown_tagged_fields = value;
239        self
240    }
241    /// Inserts an entry into unknown_tagged_fields.
242    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/// Valid versions: 0
331#[non_exhaustive]
332#[derive(Debug, Clone, PartialEq)]
333pub struct ReassignableTopicResponse {
334    /// The topic name
335    ///
336    /// Supported API versions: 0
337    pub name: super::TopicName,
338
339    /// The responses to partitions to reassign
340    ///
341    /// Supported API versions: 0
342    pub partitions: Vec<ReassignablePartitionResponse>,
343
344    /// Other tagged fields
345    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
346}
347
348impl ReassignableTopicResponse {
349    /// Sets `name` to the passed value.
350    ///
351    /// The topic name
352    ///
353    /// Supported API versions: 0
354    pub fn with_name(mut self, value: super::TopicName) -> Self {
355        self.name = value;
356        self
357    }
358    /// Sets `partitions` to the passed value.
359    ///
360    /// The responses to partitions to reassign
361    ///
362    /// Supported API versions: 0
363    pub fn with_partitions(mut self, value: Vec<ReassignablePartitionResponse>) -> Self {
364        self.partitions = value;
365        self
366    }
367    /// Sets unknown_tagged_fields to the passed value.
368    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
369        self.unknown_tagged_fields = value;
370        self
371    }
372    /// Inserts an entry into unknown_tagged_fields.
373    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}