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 types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?;
59 let num_tagged_fields = self.unknown_tagged_fields.len();
60 if num_tagged_fields > std::u32::MAX as usize {
61 bail!(
62 "Too many tagged fields to encode ({} fields)",
63 num_tagged_fields
64 );
65 }
66 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
67
68 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
69 Ok(())
70 }
71 fn compute_size(&self, version: i16) -> Result<usize> {
72 let mut total_size = 0;
73 total_size += types::CompactArray(types::Struct { version }).compute_size(&self.topics)?;
74 let num_tagged_fields = self.unknown_tagged_fields.len();
75 if num_tagged_fields > std::u32::MAX as usize {
76 bail!(
77 "Too many tagged fields to encode ({} fields)",
78 num_tagged_fields
79 );
80 }
81 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
82
83 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
84 Ok(total_size)
85 }
86}
87
88#[cfg(feature = "broker")]
89impl Decodable for DescribeQuorumRequest {
90 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
91 let topics = types::CompactArray(types::Struct { version }).decode(buf)?;
92 let mut unknown_tagged_fields = BTreeMap::new();
93 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
94 for _ in 0..num_tagged_fields {
95 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
96 let size: u32 = types::UnsignedVarInt.decode(buf)?;
97 let unknown_value = buf.try_get_bytes(size as usize)?;
98 unknown_tagged_fields.insert(tag as i32, unknown_value);
99 }
100 Ok(Self {
101 topics,
102 unknown_tagged_fields,
103 })
104 }
105}
106
107impl Default for DescribeQuorumRequest {
108 fn default() -> Self {
109 Self {
110 topics: Default::default(),
111 unknown_tagged_fields: BTreeMap::new(),
112 }
113 }
114}
115
116impl Message for DescribeQuorumRequest {
117 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
118 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
119}
120
121#[non_exhaustive]
123#[derive(Debug, Clone, PartialEq)]
124pub struct PartitionData {
125 pub partition_index: i32,
129
130 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
132}
133
134impl PartitionData {
135 pub fn with_partition_index(mut self, value: i32) -> Self {
141 self.partition_index = value;
142 self
143 }
144 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
146 self.unknown_tagged_fields = value;
147 self
148 }
149 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
151 self.unknown_tagged_fields.insert(key, value);
152 self
153 }
154}
155
156#[cfg(feature = "client")]
157impl Encodable for PartitionData {
158 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
159 types::Int32.encode(buf, &self.partition_index)?;
160 let num_tagged_fields = self.unknown_tagged_fields.len();
161 if num_tagged_fields > std::u32::MAX as usize {
162 bail!(
163 "Too many tagged fields to encode ({} fields)",
164 num_tagged_fields
165 );
166 }
167 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
168
169 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
170 Ok(())
171 }
172 fn compute_size(&self, version: i16) -> Result<usize> {
173 let mut total_size = 0;
174 total_size += types::Int32.compute_size(&self.partition_index)?;
175 let num_tagged_fields = self.unknown_tagged_fields.len();
176 if num_tagged_fields > std::u32::MAX as usize {
177 bail!(
178 "Too many tagged fields to encode ({} fields)",
179 num_tagged_fields
180 );
181 }
182 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
183
184 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
185 Ok(total_size)
186 }
187}
188
189#[cfg(feature = "broker")]
190impl Decodable for PartitionData {
191 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
192 let partition_index = types::Int32.decode(buf)?;
193 let mut unknown_tagged_fields = BTreeMap::new();
194 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
195 for _ in 0..num_tagged_fields {
196 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
197 let size: u32 = types::UnsignedVarInt.decode(buf)?;
198 let unknown_value = buf.try_get_bytes(size as usize)?;
199 unknown_tagged_fields.insert(tag as i32, unknown_value);
200 }
201 Ok(Self {
202 partition_index,
203 unknown_tagged_fields,
204 })
205 }
206}
207
208impl Default for PartitionData {
209 fn default() -> Self {
210 Self {
211 partition_index: 0,
212 unknown_tagged_fields: BTreeMap::new(),
213 }
214 }
215}
216
217impl Message for PartitionData {
218 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
219 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
220}
221
222#[non_exhaustive]
224#[derive(Debug, Clone, PartialEq)]
225pub struct TopicData {
226 pub topic_name: super::TopicName,
230
231 pub partitions: Vec<PartitionData>,
235
236 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
238}
239
240impl TopicData {
241 pub fn with_topic_name(mut self, value: super::TopicName) -> Self {
247 self.topic_name = value;
248 self
249 }
250 pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
256 self.partitions = value;
257 self
258 }
259 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
261 self.unknown_tagged_fields = value;
262 self
263 }
264 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
266 self.unknown_tagged_fields.insert(key, value);
267 self
268 }
269}
270
271#[cfg(feature = "client")]
272impl Encodable for TopicData {
273 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
274 types::CompactString.encode(buf, &self.topic_name)?;
275 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
276 let num_tagged_fields = self.unknown_tagged_fields.len();
277 if num_tagged_fields > std::u32::MAX as usize {
278 bail!(
279 "Too many tagged fields to encode ({} fields)",
280 num_tagged_fields
281 );
282 }
283 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
284
285 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
286 Ok(())
287 }
288 fn compute_size(&self, version: i16) -> Result<usize> {
289 let mut total_size = 0;
290 total_size += types::CompactString.compute_size(&self.topic_name)?;
291 total_size +=
292 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
293 let num_tagged_fields = self.unknown_tagged_fields.len();
294 if num_tagged_fields > std::u32::MAX as usize {
295 bail!(
296 "Too many tagged fields to encode ({} fields)",
297 num_tagged_fields
298 );
299 }
300 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
301
302 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
303 Ok(total_size)
304 }
305}
306
307#[cfg(feature = "broker")]
308impl Decodable for TopicData {
309 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
310 let topic_name = types::CompactString.decode(buf)?;
311 let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
312 let mut unknown_tagged_fields = BTreeMap::new();
313 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
314 for _ in 0..num_tagged_fields {
315 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
316 let size: u32 = types::UnsignedVarInt.decode(buf)?;
317 let unknown_value = buf.try_get_bytes(size as usize)?;
318 unknown_tagged_fields.insert(tag as i32, unknown_value);
319 }
320 Ok(Self {
321 topic_name,
322 partitions,
323 unknown_tagged_fields,
324 })
325 }
326}
327
328impl Default for TopicData {
329 fn default() -> Self {
330 Self {
331 topic_name: Default::default(),
332 partitions: Default::default(),
333 unknown_tagged_fields: BTreeMap::new(),
334 }
335 }
336}
337
338impl Message for TopicData {
339 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
340 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
341}
342
343impl HeaderVersion for DescribeQuorumRequest {
344 fn header_version(version: i16) -> i16 {
345 2
346 }
347}