kafka_protocol/messages/
end_quorum_epoch_request.rs

1//! EndQuorumEpochRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/EndQuorumEpochRequest.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 EndQuorumEpochRequest {
24    ///
25    ///
26    /// Supported API versions: 0
27    pub cluster_id: Option<StrBytes>,
28
29    ///
30    ///
31    /// Supported API versions: 0
32    pub topics: Vec<TopicData>,
33}
34
35impl EndQuorumEpochRequest {
36    /// Sets `cluster_id` to the passed value.
37    ///
38    ///
39    ///
40    /// Supported API versions: 0
41    pub fn with_cluster_id(mut self, value: Option<StrBytes>) -> Self {
42        self.cluster_id = value;
43        self
44    }
45    /// Sets `topics` to the passed value.
46    ///
47    ///
48    ///
49    /// Supported API versions: 0
50    pub fn with_topics(mut self, value: Vec<TopicData>) -> Self {
51        self.topics = value;
52        self
53    }
54}
55
56#[cfg(feature = "client")]
57impl Encodable for EndQuorumEpochRequest {
58    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
59        types::String.encode(buf, &self.cluster_id)?;
60        types::Array(types::Struct { version }).encode(buf, &self.topics)?;
61
62        Ok(())
63    }
64    fn compute_size(&self, version: i16) -> Result<usize> {
65        let mut total_size = 0;
66        total_size += types::String.compute_size(&self.cluster_id)?;
67        total_size += types::Array(types::Struct { version }).compute_size(&self.topics)?;
68
69        Ok(total_size)
70    }
71}
72
73#[cfg(feature = "broker")]
74impl Decodable for EndQuorumEpochRequest {
75    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
76        let cluster_id = types::String.decode(buf)?;
77        let topics = types::Array(types::Struct { version }).decode(buf)?;
78        Ok(Self { cluster_id, topics })
79    }
80}
81
82impl Default for EndQuorumEpochRequest {
83    fn default() -> Self {
84        Self {
85            cluster_id: None,
86            topics: Default::default(),
87        }
88    }
89}
90
91impl Message for EndQuorumEpochRequest {
92    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
93    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
94}
95
96/// Valid versions: 0
97#[non_exhaustive]
98#[derive(Debug, Clone, PartialEq)]
99pub struct PartitionData {
100    /// The partition index.
101    ///
102    /// Supported API versions: 0
103    pub partition_index: i32,
104
105    /// The current leader ID that is resigning
106    ///
107    /// Supported API versions: 0
108    pub leader_id: super::BrokerId,
109
110    /// The current epoch
111    ///
112    /// Supported API versions: 0
113    pub leader_epoch: i32,
114
115    /// A sorted list of preferred successors to start the election
116    ///
117    /// Supported API versions: 0
118    pub preferred_successors: Vec<i32>,
119}
120
121impl PartitionData {
122    /// Sets `partition_index` to the passed value.
123    ///
124    /// The partition index.
125    ///
126    /// Supported API versions: 0
127    pub fn with_partition_index(mut self, value: i32) -> Self {
128        self.partition_index = value;
129        self
130    }
131    /// Sets `leader_id` to the passed value.
132    ///
133    /// The current leader ID that is resigning
134    ///
135    /// Supported API versions: 0
136    pub fn with_leader_id(mut self, value: super::BrokerId) -> Self {
137        self.leader_id = value;
138        self
139    }
140    /// Sets `leader_epoch` to the passed value.
141    ///
142    /// The current epoch
143    ///
144    /// Supported API versions: 0
145    pub fn with_leader_epoch(mut self, value: i32) -> Self {
146        self.leader_epoch = value;
147        self
148    }
149    /// Sets `preferred_successors` to the passed value.
150    ///
151    /// A sorted list of preferred successors to start the election
152    ///
153    /// Supported API versions: 0
154    pub fn with_preferred_successors(mut self, value: Vec<i32>) -> Self {
155        self.preferred_successors = value;
156        self
157    }
158}
159
160#[cfg(feature = "client")]
161impl Encodable for PartitionData {
162    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
163        types::Int32.encode(buf, &self.partition_index)?;
164        types::Int32.encode(buf, &self.leader_id)?;
165        types::Int32.encode(buf, &self.leader_epoch)?;
166        types::Array(types::Int32).encode(buf, &self.preferred_successors)?;
167
168        Ok(())
169    }
170    fn compute_size(&self, version: i16) -> Result<usize> {
171        let mut total_size = 0;
172        total_size += types::Int32.compute_size(&self.partition_index)?;
173        total_size += types::Int32.compute_size(&self.leader_id)?;
174        total_size += types::Int32.compute_size(&self.leader_epoch)?;
175        total_size += types::Array(types::Int32).compute_size(&self.preferred_successors)?;
176
177        Ok(total_size)
178    }
179}
180
181#[cfg(feature = "broker")]
182impl Decodable for PartitionData {
183    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
184        let partition_index = types::Int32.decode(buf)?;
185        let leader_id = types::Int32.decode(buf)?;
186        let leader_epoch = types::Int32.decode(buf)?;
187        let preferred_successors = types::Array(types::Int32).decode(buf)?;
188        Ok(Self {
189            partition_index,
190            leader_id,
191            leader_epoch,
192            preferred_successors,
193        })
194    }
195}
196
197impl Default for PartitionData {
198    fn default() -> Self {
199        Self {
200            partition_index: 0,
201            leader_id: (0).into(),
202            leader_epoch: 0,
203            preferred_successors: Default::default(),
204        }
205    }
206}
207
208impl Message for PartitionData {
209    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
210    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
211}
212
213/// Valid versions: 0
214#[non_exhaustive]
215#[derive(Debug, Clone, PartialEq)]
216pub struct TopicData {
217    /// The topic name.
218    ///
219    /// Supported API versions: 0
220    pub topic_name: super::TopicName,
221
222    ///
223    ///
224    /// Supported API versions: 0
225    pub partitions: Vec<PartitionData>,
226}
227
228impl TopicData {
229    /// Sets `topic_name` to the passed value.
230    ///
231    /// The topic name.
232    ///
233    /// Supported API versions: 0
234    pub fn with_topic_name(mut self, value: super::TopicName) -> Self {
235        self.topic_name = value;
236        self
237    }
238    /// Sets `partitions` to the passed value.
239    ///
240    ///
241    ///
242    /// Supported API versions: 0
243    pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
244        self.partitions = value;
245        self
246    }
247}
248
249#[cfg(feature = "client")]
250impl Encodable for TopicData {
251    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
252        types::String.encode(buf, &self.topic_name)?;
253        types::Array(types::Struct { version }).encode(buf, &self.partitions)?;
254
255        Ok(())
256    }
257    fn compute_size(&self, version: i16) -> Result<usize> {
258        let mut total_size = 0;
259        total_size += types::String.compute_size(&self.topic_name)?;
260        total_size += types::Array(types::Struct { version }).compute_size(&self.partitions)?;
261
262        Ok(total_size)
263    }
264}
265
266#[cfg(feature = "broker")]
267impl Decodable for TopicData {
268    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
269        let topic_name = types::String.decode(buf)?;
270        let partitions = types::Array(types::Struct { version }).decode(buf)?;
271        Ok(Self {
272            topic_name,
273            partitions,
274        })
275    }
276}
277
278impl Default for TopicData {
279    fn default() -> Self {
280        Self {
281            topic_name: Default::default(),
282            partitions: Default::default(),
283        }
284    }
285}
286
287impl Message for TopicData {
288    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
289    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
290}
291
292impl HeaderVersion for EndQuorumEpochRequest {
293    fn header_version(version: i16) -> i16 {
294        1
295    }
296}