kafka_protocol/messages/
end_quorum_epoch_request.rs1#![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#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct EndQuorumEpochRequest {
24 pub cluster_id: Option<StrBytes>,
28
29 pub topics: Vec<TopicData>,
33}
34
35impl EndQuorumEpochRequest {
36 pub fn with_cluster_id(mut self, value: Option<StrBytes>) -> Self {
42 self.cluster_id = value;
43 self
44 }
45 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#[non_exhaustive]
98#[derive(Debug, Clone, PartialEq)]
99pub struct PartitionData {
100 pub partition_index: i32,
104
105 pub leader_id: super::BrokerId,
109
110 pub leader_epoch: i32,
114
115 pub preferred_successors: Vec<i32>,
119}
120
121impl PartitionData {
122 pub fn with_partition_index(mut self, value: i32) -> Self {
128 self.partition_index = value;
129 self
130 }
131 pub fn with_leader_id(mut self, value: super::BrokerId) -> Self {
137 self.leader_id = value;
138 self
139 }
140 pub fn with_leader_epoch(mut self, value: i32) -> Self {
146 self.leader_epoch = value;
147 self
148 }
149 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#[non_exhaustive]
215#[derive(Debug, Clone, PartialEq)]
216pub struct TopicData {
217 pub topic_name: super::TopicName,
221
222 pub partitions: Vec<PartitionData>,
226}
227
228impl TopicData {
229 pub fn with_topic_name(mut self, value: super::TopicName) -> Self {
235 self.topic_name = value;
236 self
237 }
238 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}