kafka_protocol/messages/
list_partition_reassignments_request.rs

1//! ListPartitionReassignmentsRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/ListPartitionReassignmentsRequest.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 ListPartitionReassignmentsRequest {
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 list partition reassignments for, or null to list everything.
30    ///
31    /// Supported API versions: 0
32    pub topics: Option<Vec<ListPartitionReassignmentsTopics>>,
33
34    /// Other tagged fields
35    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl ListPartitionReassignmentsRequest {
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 list partition reassignments for, or null to list everything.
51    ///
52    /// Supported API versions: 0
53    pub fn with_topics(mut self, value: Option<Vec<ListPartitionReassignmentsTopics>>) -> 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 ListPartitionReassignmentsRequest {
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 ListPartitionReassignmentsRequest {
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 ListPartitionReassignmentsRequest {
132    fn default() -> Self {
133        Self {
134            timeout_ms: 60000,
135            topics: None,
136            unknown_tagged_fields: BTreeMap::new(),
137        }
138    }
139}
140
141impl Message for ListPartitionReassignmentsRequest {
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 ListPartitionReassignmentsTopics {
150    /// The topic name
151    ///
152    /// Supported API versions: 0
153    pub name: super::TopicName,
154
155    /// The partitions to list partition reassignments for.
156    ///
157    /// Supported API versions: 0
158    pub partition_indexes: Vec<i32>,
159
160    /// Other tagged fields
161    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
162}
163
164impl ListPartitionReassignmentsTopics {
165    /// Sets `name` to the passed value.
166    ///
167    /// The topic name
168    ///
169    /// Supported API versions: 0
170    pub fn with_name(mut self, value: super::TopicName) -> Self {
171        self.name = value;
172        self
173    }
174    /// Sets `partition_indexes` to the passed value.
175    ///
176    /// The partitions to list partition reassignments for.
177    ///
178    /// Supported API versions: 0
179    pub fn with_partition_indexes(mut self, value: Vec<i32>) -> Self {
180        self.partition_indexes = 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 ListPartitionReassignmentsTopics {
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::CompactString.encode(buf, &self.name)?;
202        types::CompactArray(types::Int32).encode(buf, &self.partition_indexes)?;
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::CompactString.compute_size(&self.name)?;
218        total_size += types::CompactArray(types::Int32).compute_size(&self.partition_indexes)?;
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 ListPartitionReassignmentsTopics {
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 name = types::CompactString.decode(buf)?;
240        let partition_indexes = 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            name,
251            partition_indexes,
252            unknown_tagged_fields,
253        })
254    }
255}
256
257impl Default for ListPartitionReassignmentsTopics {
258    fn default() -> Self {
259        Self {
260            name: Default::default(),
261            partition_indexes: Default::default(),
262            unknown_tagged_fields: BTreeMap::new(),
263        }
264    }
265}
266
267impl Message for ListPartitionReassignmentsTopics {
268    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
269    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
270}
271
272impl HeaderVersion for ListPartitionReassignmentsRequest {
273    fn header_version(version: i16) -> i16 {
274        2
275    }
276}