1#![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 DescribeQuorumRequest {
24 pub topics: Vec<TopicData>,
28
29 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
31}
32
33impl DescribeQuorumRequest {
34 pub fn with_topics(mut self, value: Vec<TopicData>) -> Self {
40 self.topics = value;
41 self
42 }
43 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
45 self.unknown_tagged_fields = value;
46 self
47 }
48 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
50 self.unknown_tagged_fields.insert(key, value);
51 self
52 }
53}
54
55#[cfg(feature = "client")]
56impl Encodable for DescribeQuorumRequest {
57 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
58 if version < 0 || version > 2 {
59 bail!("specified version not supported by this message type");
60 }
61 types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?;
62 let num_tagged_fields = self.unknown_tagged_fields.len();
63 if num_tagged_fields > std::u32::MAX as usize {
64 bail!(
65 "Too many tagged fields to encode ({} fields)",
66 num_tagged_fields
67 );
68 }
69 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
70
71 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
72 Ok(())
73 }
74 fn compute_size(&self, version: i16) -> Result<usize> {
75 let mut total_size = 0;
76 total_size += types::CompactArray(types::Struct { version }).compute_size(&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 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
85
86 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
87 Ok(total_size)
88 }
89}
90
91#[cfg(feature = "broker")]
92impl Decodable for DescribeQuorumRequest {
93 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
94 if version < 0 || version > 2 {
95 bail!("specified version not supported by this message type");
96 }
97 let topics = types::CompactArray(types::Struct { version }).decode(buf)?;
98 let mut unknown_tagged_fields = BTreeMap::new();
99 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
100 for _ in 0..num_tagged_fields {
101 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
102 let size: u32 = types::UnsignedVarInt.decode(buf)?;
103 let unknown_value = buf.try_get_bytes(size as usize)?;
104 unknown_tagged_fields.insert(tag as i32, unknown_value);
105 }
106 Ok(Self {
107 topics,
108 unknown_tagged_fields,
109 })
110 }
111}
112
113impl Default for DescribeQuorumRequest {
114 fn default() -> Self {
115 Self {
116 topics: Default::default(),
117 unknown_tagged_fields: BTreeMap::new(),
118 }
119 }
120}
121
122impl Message for DescribeQuorumRequest {
123 const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
124 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
125}
126
127#[non_exhaustive]
129#[derive(Debug, Clone, PartialEq)]
130pub struct PartitionData {
131 pub partition_index: i32,
135
136 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
138}
139
140impl PartitionData {
141 pub fn with_partition_index(mut self, value: i32) -> Self {
147 self.partition_index = value;
148 self
149 }
150 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
152 self.unknown_tagged_fields = value;
153 self
154 }
155 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
157 self.unknown_tagged_fields.insert(key, value);
158 self
159 }
160}
161
162#[cfg(feature = "client")]
163impl Encodable for PartitionData {
164 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
165 if version < 0 || version > 2 {
166 bail!("specified version not supported by this message type");
167 }
168 types::Int32.encode(buf, &self.partition_index)?;
169 let num_tagged_fields = self.unknown_tagged_fields.len();
170 if num_tagged_fields > std::u32::MAX as usize {
171 bail!(
172 "Too many tagged fields to encode ({} fields)",
173 num_tagged_fields
174 );
175 }
176 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
177
178 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
179 Ok(())
180 }
181 fn compute_size(&self, version: i16) -> Result<usize> {
182 let mut total_size = 0;
183 total_size += types::Int32.compute_size(&self.partition_index)?;
184 let num_tagged_fields = self.unknown_tagged_fields.len();
185 if num_tagged_fields > std::u32::MAX as usize {
186 bail!(
187 "Too many tagged fields to encode ({} fields)",
188 num_tagged_fields
189 );
190 }
191 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
192
193 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
194 Ok(total_size)
195 }
196}
197
198#[cfg(feature = "broker")]
199impl Decodable for PartitionData {
200 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
201 if version < 0 || version > 2 {
202 bail!("specified version not supported by this message type");
203 }
204 let partition_index = types::Int32.decode(buf)?;
205 let mut unknown_tagged_fields = BTreeMap::new();
206 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
207 for _ in 0..num_tagged_fields {
208 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
209 let size: u32 = types::UnsignedVarInt.decode(buf)?;
210 let unknown_value = buf.try_get_bytes(size as usize)?;
211 unknown_tagged_fields.insert(tag as i32, unknown_value);
212 }
213 Ok(Self {
214 partition_index,
215 unknown_tagged_fields,
216 })
217 }
218}
219
220impl Default for PartitionData {
221 fn default() -> Self {
222 Self {
223 partition_index: 0,
224 unknown_tagged_fields: BTreeMap::new(),
225 }
226 }
227}
228
229impl Message for PartitionData {
230 const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
231 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
232}
233
234#[non_exhaustive]
236#[derive(Debug, Clone, PartialEq)]
237pub struct TopicData {
238 pub topic_name: super::TopicName,
242
243 pub partitions: Vec<PartitionData>,
247
248 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
250}
251
252impl TopicData {
253 pub fn with_topic_name(mut self, value: super::TopicName) -> Self {
259 self.topic_name = value;
260 self
261 }
262 pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
268 self.partitions = value;
269 self
270 }
271 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
273 self.unknown_tagged_fields = value;
274 self
275 }
276 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
278 self.unknown_tagged_fields.insert(key, value);
279 self
280 }
281}
282
283#[cfg(feature = "client")]
284impl Encodable for TopicData {
285 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
286 if version < 0 || version > 2 {
287 bail!("specified version not supported by this message type");
288 }
289 types::CompactString.encode(buf, &self.topic_name)?;
290 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
291 let num_tagged_fields = self.unknown_tagged_fields.len();
292 if num_tagged_fields > std::u32::MAX as usize {
293 bail!(
294 "Too many tagged fields to encode ({} fields)",
295 num_tagged_fields
296 );
297 }
298 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
299
300 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
301 Ok(())
302 }
303 fn compute_size(&self, version: i16) -> Result<usize> {
304 let mut total_size = 0;
305 total_size += types::CompactString.compute_size(&self.topic_name)?;
306 total_size +=
307 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
308 let num_tagged_fields = self.unknown_tagged_fields.len();
309 if num_tagged_fields > std::u32::MAX as usize {
310 bail!(
311 "Too many tagged fields to encode ({} fields)",
312 num_tagged_fields
313 );
314 }
315 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
316
317 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
318 Ok(total_size)
319 }
320}
321
322#[cfg(feature = "broker")]
323impl Decodable for TopicData {
324 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
325 if version < 0 || version > 2 {
326 bail!("specified version not supported by this message type");
327 }
328 let topic_name = types::CompactString.decode(buf)?;
329 let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
330 let mut unknown_tagged_fields = BTreeMap::new();
331 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
332 for _ in 0..num_tagged_fields {
333 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
334 let size: u32 = types::UnsignedVarInt.decode(buf)?;
335 let unknown_value = buf.try_get_bytes(size as usize)?;
336 unknown_tagged_fields.insert(tag as i32, unknown_value);
337 }
338 Ok(Self {
339 topic_name,
340 partitions,
341 unknown_tagged_fields,
342 })
343 }
344}
345
346impl Default for TopicData {
347 fn default() -> Self {
348 Self {
349 topic_name: Default::default(),
350 partitions: Default::default(),
351 unknown_tagged_fields: BTreeMap::new(),
352 }
353 }
354}
355
356impl Message for TopicData {
357 const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
358 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
359}
360
361impl HeaderVersion for DescribeQuorumRequest {
362 fn header_version(version: i16) -> i16 {
363 2
364 }
365}