kafka_protocol/messages/
alter_partition_reassignments_request.rs

1//! AlterPartitionReassignmentsRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/AlterPartitionReassignmentsRequest.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 AlterPartitionReassignmentsRequest {
24    /// The time in ms to wait for the request to complete.
25    ///
26    /// Supported API versions: 0
27    pub timeout_ms: i32,
28
29    /// The topics to reassign.
30    ///
31    /// Supported API versions: 0
32    pub topics: Vec<ReassignableTopic>,
33
34    /// Other tagged fields
35    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl AlterPartitionReassignmentsRequest {
39    /// Sets `timeout_ms` to the passed value.
40    ///
41    /// The time in ms to wait for the request to complete.
42    ///
43    /// Supported API versions: 0
44    pub fn with_timeout_ms(mut self, value: i32) -> Self {
45        self.timeout_ms = value;
46        self
47    }
48    /// Sets `topics` to the passed value.
49    ///
50    /// The topics to reassign.
51    ///
52    /// Supported API versions: 0
53    pub fn with_topics(mut self, value: Vec<ReassignableTopic>) -> Self {
54        self.topics = value;
55        self
56    }
57    /// Sets unknown_tagged_fields to the passed value.
58    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
59        self.unknown_tagged_fields = value;
60        self
61    }
62    /// Inserts an entry into unknown_tagged_fields.
63    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
64        self.unknown_tagged_fields.insert(key, value);
65        self
66    }
67}
68
69#[cfg(feature = "client")]
70impl Encodable for AlterPartitionReassignmentsRequest {
71    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
72        if version != 0 {
73            bail!("specified version not supported by this message type");
74        }
75        types::Int32.encode(buf, &self.timeout_ms)?;
76        types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?;
77        let num_tagged_fields = self.unknown_tagged_fields.len();
78        if num_tagged_fields > std::u32::MAX as usize {
79            bail!(
80                "Too many tagged fields to encode ({} fields)",
81                num_tagged_fields
82            );
83        }
84        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
85
86        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
87        Ok(())
88    }
89    fn compute_size(&self, version: i16) -> Result<usize> {
90        let mut total_size = 0;
91        total_size += types::Int32.compute_size(&self.timeout_ms)?;
92        total_size += types::CompactArray(types::Struct { version }).compute_size(&self.topics)?;
93        let num_tagged_fields = self.unknown_tagged_fields.len();
94        if num_tagged_fields > std::u32::MAX as usize {
95            bail!(
96                "Too many tagged fields to encode ({} fields)",
97                num_tagged_fields
98            );
99        }
100        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
101
102        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
103        Ok(total_size)
104    }
105}
106
107#[cfg(feature = "broker")]
108impl Decodable for AlterPartitionReassignmentsRequest {
109    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
110        if version != 0 {
111            bail!("specified version not supported by this message type");
112        }
113        let timeout_ms = types::Int32.decode(buf)?;
114        let topics = types::CompactArray(types::Struct { version }).decode(buf)?;
115        let mut unknown_tagged_fields = BTreeMap::new();
116        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
117        for _ in 0..num_tagged_fields {
118            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
119            let size: u32 = types::UnsignedVarInt.decode(buf)?;
120            let unknown_value = buf.try_get_bytes(size as usize)?;
121            unknown_tagged_fields.insert(tag as i32, unknown_value);
122        }
123        Ok(Self {
124            timeout_ms,
125            topics,
126            unknown_tagged_fields,
127        })
128    }
129}
130
131impl Default for AlterPartitionReassignmentsRequest {
132    fn default() -> Self {
133        Self {
134            timeout_ms: 60000,
135            topics: Default::default(),
136            unknown_tagged_fields: BTreeMap::new(),
137        }
138    }
139}
140
141impl Message for AlterPartitionReassignmentsRequest {
142    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
143    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
144}
145
146/// Valid versions: 0
147#[non_exhaustive]
148#[derive(Debug, Clone, PartialEq)]
149pub struct ReassignablePartition {
150    /// The partition index.
151    ///
152    /// Supported API versions: 0
153    pub partition_index: i32,
154
155    /// The replicas to place the partitions on, or null to cancel a pending reassignment for this partition.
156    ///
157    /// Supported API versions: 0
158    pub replicas: Option<Vec<super::BrokerId>>,
159
160    /// Other tagged fields
161    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
162}
163
164impl ReassignablePartition {
165    /// Sets `partition_index` to the passed value.
166    ///
167    /// The partition index.
168    ///
169    /// Supported API versions: 0
170    pub fn with_partition_index(mut self, value: i32) -> Self {
171        self.partition_index = value;
172        self
173    }
174    /// Sets `replicas` to the passed value.
175    ///
176    /// The replicas to place the partitions on, or null to cancel a pending reassignment for this partition.
177    ///
178    /// Supported API versions: 0
179    pub fn with_replicas(mut self, value: Option<Vec<super::BrokerId>>) -> Self {
180        self.replicas = value;
181        self
182    }
183    /// Sets unknown_tagged_fields to the passed value.
184    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
185        self.unknown_tagged_fields = value;
186        self
187    }
188    /// Inserts an entry into unknown_tagged_fields.
189    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
190        self.unknown_tagged_fields.insert(key, value);
191        self
192    }
193}
194
195#[cfg(feature = "client")]
196impl Encodable for ReassignablePartition {
197    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
198        if version != 0 {
199            bail!("specified version not supported by this message type");
200        }
201        types::Int32.encode(buf, &self.partition_index)?;
202        types::CompactArray(types::Int32).encode(buf, &self.replicas)?;
203        let num_tagged_fields = self.unknown_tagged_fields.len();
204        if num_tagged_fields > std::u32::MAX as usize {
205            bail!(
206                "Too many tagged fields to encode ({} fields)",
207                num_tagged_fields
208            );
209        }
210        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
211
212        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
213        Ok(())
214    }
215    fn compute_size(&self, version: i16) -> Result<usize> {
216        let mut total_size = 0;
217        total_size += types::Int32.compute_size(&self.partition_index)?;
218        total_size += types::CompactArray(types::Int32).compute_size(&self.replicas)?;
219        let num_tagged_fields = self.unknown_tagged_fields.len();
220        if num_tagged_fields > std::u32::MAX as usize {
221            bail!(
222                "Too many tagged fields to encode ({} fields)",
223                num_tagged_fields
224            );
225        }
226        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
227
228        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
229        Ok(total_size)
230    }
231}
232
233#[cfg(feature = "broker")]
234impl Decodable for ReassignablePartition {
235    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
236        if version != 0 {
237            bail!("specified version not supported by this message type");
238        }
239        let partition_index = types::Int32.decode(buf)?;
240        let replicas = types::CompactArray(types::Int32).decode(buf)?;
241        let mut unknown_tagged_fields = BTreeMap::new();
242        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
243        for _ in 0..num_tagged_fields {
244            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
245            let size: u32 = types::UnsignedVarInt.decode(buf)?;
246            let unknown_value = buf.try_get_bytes(size as usize)?;
247            unknown_tagged_fields.insert(tag as i32, unknown_value);
248        }
249        Ok(Self {
250            partition_index,
251            replicas,
252            unknown_tagged_fields,
253        })
254    }
255}
256
257impl Default for ReassignablePartition {
258    fn default() -> Self {
259        Self {
260            partition_index: 0,
261            replicas: None,
262            unknown_tagged_fields: BTreeMap::new(),
263        }
264    }
265}
266
267impl Message for ReassignablePartition {
268    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
269    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
270}
271
272/// Valid versions: 0
273#[non_exhaustive]
274#[derive(Debug, Clone, PartialEq)]
275pub struct ReassignableTopic {
276    /// The topic name.
277    ///
278    /// Supported API versions: 0
279    pub name: super::TopicName,
280
281    /// The partitions to reassign.
282    ///
283    /// Supported API versions: 0
284    pub partitions: Vec<ReassignablePartition>,
285
286    /// Other tagged fields
287    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
288}
289
290impl ReassignableTopic {
291    /// Sets `name` to the passed value.
292    ///
293    /// The topic name.
294    ///
295    /// Supported API versions: 0
296    pub fn with_name(mut self, value: super::TopicName) -> Self {
297        self.name = value;
298        self
299    }
300    /// Sets `partitions` to the passed value.
301    ///
302    /// The partitions to reassign.
303    ///
304    /// Supported API versions: 0
305    pub fn with_partitions(mut self, value: Vec<ReassignablePartition>) -> Self {
306        self.partitions = value;
307        self
308    }
309    /// Sets unknown_tagged_fields to the passed value.
310    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
311        self.unknown_tagged_fields = value;
312        self
313    }
314    /// Inserts an entry into unknown_tagged_fields.
315    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
316        self.unknown_tagged_fields.insert(key, value);
317        self
318    }
319}
320
321#[cfg(feature = "client")]
322impl Encodable for ReassignableTopic {
323    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
324        if version != 0 {
325            bail!("specified version not supported by this message type");
326        }
327        types::CompactString.encode(buf, &self.name)?;
328        types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
329        let num_tagged_fields = self.unknown_tagged_fields.len();
330        if num_tagged_fields > std::u32::MAX as usize {
331            bail!(
332                "Too many tagged fields to encode ({} fields)",
333                num_tagged_fields
334            );
335        }
336        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
337
338        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
339        Ok(())
340    }
341    fn compute_size(&self, version: i16) -> Result<usize> {
342        let mut total_size = 0;
343        total_size += types::CompactString.compute_size(&self.name)?;
344        total_size +=
345            types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
346        let num_tagged_fields = self.unknown_tagged_fields.len();
347        if num_tagged_fields > std::u32::MAX as usize {
348            bail!(
349                "Too many tagged fields to encode ({} fields)",
350                num_tagged_fields
351            );
352        }
353        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
354
355        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
356        Ok(total_size)
357    }
358}
359
360#[cfg(feature = "broker")]
361impl Decodable for ReassignableTopic {
362    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
363        if version != 0 {
364            bail!("specified version not supported by this message type");
365        }
366        let name = types::CompactString.decode(buf)?;
367        let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
368        let mut unknown_tagged_fields = BTreeMap::new();
369        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
370        for _ in 0..num_tagged_fields {
371            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
372            let size: u32 = types::UnsignedVarInt.decode(buf)?;
373            let unknown_value = buf.try_get_bytes(size as usize)?;
374            unknown_tagged_fields.insert(tag as i32, unknown_value);
375        }
376        Ok(Self {
377            name,
378            partitions,
379            unknown_tagged_fields,
380        })
381    }
382}
383
384impl Default for ReassignableTopic {
385    fn default() -> Self {
386        Self {
387            name: Default::default(),
388            partitions: Default::default(),
389            unknown_tagged_fields: BTreeMap::new(),
390        }
391    }
392}
393
394impl Message for ReassignableTopic {
395    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
396    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
397}
398
399impl HeaderVersion for AlterPartitionReassignmentsRequest {
400    fn header_version(version: i16) -> i16 {
401        2
402    }
403}