kafka_protocol/messages/
begin_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 BeginQuorumEpochRequest {
24 pub cluster_id: Option<StrBytes>,
28
29 pub topics: Vec<TopicData>,
33}
34
35impl BeginQuorumEpochRequest {
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 BeginQuorumEpochRequest {
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 BeginQuorumEpochRequest {
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 BeginQuorumEpochRequest {
83 fn default() -> Self {
84 Self {
85 cluster_id: None,
86 topics: Default::default(),
87 }
88 }
89}
90
91impl Message for BeginQuorumEpochRequest {
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
116impl PartitionData {
117 pub fn with_partition_index(mut self, value: i32) -> Self {
123 self.partition_index = value;
124 self
125 }
126 pub fn with_leader_id(mut self, value: super::BrokerId) -> Self {
132 self.leader_id = value;
133 self
134 }
135 pub fn with_leader_epoch(mut self, value: i32) -> Self {
141 self.leader_epoch = value;
142 self
143 }
144}
145
146#[cfg(feature = "client")]
147impl Encodable for PartitionData {
148 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
149 types::Int32.encode(buf, &self.partition_index)?;
150 types::Int32.encode(buf, &self.leader_id)?;
151 types::Int32.encode(buf, &self.leader_epoch)?;
152
153 Ok(())
154 }
155 fn compute_size(&self, version: i16) -> Result<usize> {
156 let mut total_size = 0;
157 total_size += types::Int32.compute_size(&self.partition_index)?;
158 total_size += types::Int32.compute_size(&self.leader_id)?;
159 total_size += types::Int32.compute_size(&self.leader_epoch)?;
160
161 Ok(total_size)
162 }
163}
164
165#[cfg(feature = "broker")]
166impl Decodable for PartitionData {
167 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
168 let partition_index = types::Int32.decode(buf)?;
169 let leader_id = types::Int32.decode(buf)?;
170 let leader_epoch = types::Int32.decode(buf)?;
171 Ok(Self {
172 partition_index,
173 leader_id,
174 leader_epoch,
175 })
176 }
177}
178
179impl Default for PartitionData {
180 fn default() -> Self {
181 Self {
182 partition_index: 0,
183 leader_id: (0).into(),
184 leader_epoch: 0,
185 }
186 }
187}
188
189impl Message for PartitionData {
190 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
191 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
192}
193
194#[non_exhaustive]
196#[derive(Debug, Clone, PartialEq)]
197pub struct TopicData {
198 pub topic_name: super::TopicName,
202
203 pub partitions: Vec<PartitionData>,
207}
208
209impl TopicData {
210 pub fn with_topic_name(mut self, value: super::TopicName) -> Self {
216 self.topic_name = value;
217 self
218 }
219 pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
225 self.partitions = value;
226 self
227 }
228}
229
230#[cfg(feature = "client")]
231impl Encodable for TopicData {
232 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
233 types::String.encode(buf, &self.topic_name)?;
234 types::Array(types::Struct { version }).encode(buf, &self.partitions)?;
235
236 Ok(())
237 }
238 fn compute_size(&self, version: i16) -> Result<usize> {
239 let mut total_size = 0;
240 total_size += types::String.compute_size(&self.topic_name)?;
241 total_size += types::Array(types::Struct { version }).compute_size(&self.partitions)?;
242
243 Ok(total_size)
244 }
245}
246
247#[cfg(feature = "broker")]
248impl Decodable for TopicData {
249 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
250 let topic_name = types::String.decode(buf)?;
251 let partitions = types::Array(types::Struct { version }).decode(buf)?;
252 Ok(Self {
253 topic_name,
254 partitions,
255 })
256 }
257}
258
259impl Default for TopicData {
260 fn default() -> Self {
261 Self {
262 topic_name: Default::default(),
263 partitions: Default::default(),
264 }
265 }
266}
267
268impl Message for TopicData {
269 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
270 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
271}
272
273impl HeaderVersion for BeginQuorumEpochRequest {
274 fn header_version(version: i16) -> i16 {
275 1
276 }
277}