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 AssignReplicasToDirsResponse {
24 pub throttle_time_ms: i32,
28
29 pub error_code: i16,
33
34 pub directories: Vec<DirectoryData>,
38
39 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl AssignReplicasToDirsResponse {
44 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
50 self.throttle_time_ms = value;
51 self
52 }
53 pub fn with_error_code(mut self, value: i16) -> Self {
59 self.error_code = value;
60 self
61 }
62 pub fn with_directories(mut self, value: Vec<DirectoryData>) -> Self {
68 self.directories = value;
69 self
70 }
71 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73 self.unknown_tagged_fields = value;
74 self
75 }
76 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
78 self.unknown_tagged_fields.insert(key, value);
79 self
80 }
81}
82
83#[cfg(feature = "broker")]
84impl Encodable for AssignReplicasToDirsResponse {
85 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86 if version != 0 {
87 bail!("specified version not supported by this message type");
88 }
89 types::Int32.encode(buf, &self.throttle_time_ms)?;
90 types::Int16.encode(buf, &self.error_code)?;
91 types::CompactArray(types::Struct { version }).encode(buf, &self.directories)?;
92 let num_tagged_fields = self.unknown_tagged_fields.len();
93 if num_tagged_fields > std::u32::MAX as usize {
94 bail!(
95 "Too many tagged fields to encode ({} fields)",
96 num_tagged_fields
97 );
98 }
99 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
100
101 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
102 Ok(())
103 }
104 fn compute_size(&self, version: i16) -> Result<usize> {
105 let mut total_size = 0;
106 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
107 total_size += types::Int16.compute_size(&self.error_code)?;
108 total_size +=
109 types::CompactArray(types::Struct { version }).compute_size(&self.directories)?;
110 let num_tagged_fields = self.unknown_tagged_fields.len();
111 if num_tagged_fields > std::u32::MAX as usize {
112 bail!(
113 "Too many tagged fields to encode ({} fields)",
114 num_tagged_fields
115 );
116 }
117 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
118
119 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
120 Ok(total_size)
121 }
122}
123
124#[cfg(feature = "client")]
125impl Decodable for AssignReplicasToDirsResponse {
126 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
127 if version != 0 {
128 bail!("specified version not supported by this message type");
129 }
130 let throttle_time_ms = types::Int32.decode(buf)?;
131 let error_code = types::Int16.decode(buf)?;
132 let directories = types::CompactArray(types::Struct { version }).decode(buf)?;
133 let mut unknown_tagged_fields = BTreeMap::new();
134 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
135 for _ in 0..num_tagged_fields {
136 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
137 let size: u32 = types::UnsignedVarInt.decode(buf)?;
138 let unknown_value = buf.try_get_bytes(size as usize)?;
139 unknown_tagged_fields.insert(tag as i32, unknown_value);
140 }
141 Ok(Self {
142 throttle_time_ms,
143 error_code,
144 directories,
145 unknown_tagged_fields,
146 })
147 }
148}
149
150impl Default for AssignReplicasToDirsResponse {
151 fn default() -> Self {
152 Self {
153 throttle_time_ms: 0,
154 error_code: 0,
155 directories: Default::default(),
156 unknown_tagged_fields: BTreeMap::new(),
157 }
158 }
159}
160
161impl Message for AssignReplicasToDirsResponse {
162 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
163 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
164}
165
166#[non_exhaustive]
168#[derive(Debug, Clone, PartialEq)]
169pub struct DirectoryData {
170 pub id: Uuid,
174
175 pub topics: Vec<TopicData>,
179
180 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
182}
183
184impl DirectoryData {
185 pub fn with_id(mut self, value: Uuid) -> Self {
191 self.id = value;
192 self
193 }
194 pub fn with_topics(mut self, value: Vec<TopicData>) -> Self {
200 self.topics = value;
201 self
202 }
203 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
205 self.unknown_tagged_fields = value;
206 self
207 }
208 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
210 self.unknown_tagged_fields.insert(key, value);
211 self
212 }
213}
214
215#[cfg(feature = "broker")]
216impl Encodable for DirectoryData {
217 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
218 if version != 0 {
219 bail!("specified version not supported by this message type");
220 }
221 types::Uuid.encode(buf, &self.id)?;
222 types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?;
223 let num_tagged_fields = self.unknown_tagged_fields.len();
224 if num_tagged_fields > std::u32::MAX as usize {
225 bail!(
226 "Too many tagged fields to encode ({} fields)",
227 num_tagged_fields
228 );
229 }
230 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
231
232 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
233 Ok(())
234 }
235 fn compute_size(&self, version: i16) -> Result<usize> {
236 let mut total_size = 0;
237 total_size += types::Uuid.compute_size(&self.id)?;
238 total_size += types::CompactArray(types::Struct { version }).compute_size(&self.topics)?;
239 let num_tagged_fields = self.unknown_tagged_fields.len();
240 if num_tagged_fields > std::u32::MAX as usize {
241 bail!(
242 "Too many tagged fields to encode ({} fields)",
243 num_tagged_fields
244 );
245 }
246 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
247
248 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
249 Ok(total_size)
250 }
251}
252
253#[cfg(feature = "client")]
254impl Decodable for DirectoryData {
255 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
256 if version != 0 {
257 bail!("specified version not supported by this message type");
258 }
259 let id = types::Uuid.decode(buf)?;
260 let topics = types::CompactArray(types::Struct { version }).decode(buf)?;
261 let mut unknown_tagged_fields = BTreeMap::new();
262 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
263 for _ in 0..num_tagged_fields {
264 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
265 let size: u32 = types::UnsignedVarInt.decode(buf)?;
266 let unknown_value = buf.try_get_bytes(size as usize)?;
267 unknown_tagged_fields.insert(tag as i32, unknown_value);
268 }
269 Ok(Self {
270 id,
271 topics,
272 unknown_tagged_fields,
273 })
274 }
275}
276
277impl Default for DirectoryData {
278 fn default() -> Self {
279 Self {
280 id: Uuid::nil(),
281 topics: Default::default(),
282 unknown_tagged_fields: BTreeMap::new(),
283 }
284 }
285}
286
287impl Message for DirectoryData {
288 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
289 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
290}
291
292#[non_exhaustive]
294#[derive(Debug, Clone, PartialEq)]
295pub struct PartitionData {
296 pub partition_index: i32,
300
301 pub error_code: i16,
305
306 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
308}
309
310impl PartitionData {
311 pub fn with_partition_index(mut self, value: i32) -> Self {
317 self.partition_index = value;
318 self
319 }
320 pub fn with_error_code(mut self, value: i16) -> Self {
326 self.error_code = value;
327 self
328 }
329 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
331 self.unknown_tagged_fields = value;
332 self
333 }
334 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
336 self.unknown_tagged_fields.insert(key, value);
337 self
338 }
339}
340
341#[cfg(feature = "broker")]
342impl Encodable for PartitionData {
343 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
344 if version != 0 {
345 bail!("specified version not supported by this message type");
346 }
347 types::Int32.encode(buf, &self.partition_index)?;
348 types::Int16.encode(buf, &self.error_code)?;
349 let num_tagged_fields = self.unknown_tagged_fields.len();
350 if num_tagged_fields > std::u32::MAX as usize {
351 bail!(
352 "Too many tagged fields to encode ({} fields)",
353 num_tagged_fields
354 );
355 }
356 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
357
358 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
359 Ok(())
360 }
361 fn compute_size(&self, version: i16) -> Result<usize> {
362 let mut total_size = 0;
363 total_size += types::Int32.compute_size(&self.partition_index)?;
364 total_size += types::Int16.compute_size(&self.error_code)?;
365 let num_tagged_fields = self.unknown_tagged_fields.len();
366 if num_tagged_fields > std::u32::MAX as usize {
367 bail!(
368 "Too many tagged fields to encode ({} fields)",
369 num_tagged_fields
370 );
371 }
372 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
373
374 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
375 Ok(total_size)
376 }
377}
378
379#[cfg(feature = "client")]
380impl Decodable for PartitionData {
381 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
382 if version != 0 {
383 bail!("specified version not supported by this message type");
384 }
385 let partition_index = types::Int32.decode(buf)?;
386 let error_code = types::Int16.decode(buf)?;
387 let mut unknown_tagged_fields = BTreeMap::new();
388 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
389 for _ in 0..num_tagged_fields {
390 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
391 let size: u32 = types::UnsignedVarInt.decode(buf)?;
392 let unknown_value = buf.try_get_bytes(size as usize)?;
393 unknown_tagged_fields.insert(tag as i32, unknown_value);
394 }
395 Ok(Self {
396 partition_index,
397 error_code,
398 unknown_tagged_fields,
399 })
400 }
401}
402
403impl Default for PartitionData {
404 fn default() -> Self {
405 Self {
406 partition_index: 0,
407 error_code: 0,
408 unknown_tagged_fields: BTreeMap::new(),
409 }
410 }
411}
412
413impl Message for PartitionData {
414 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
415 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
416}
417
418#[non_exhaustive]
420#[derive(Debug, Clone, PartialEq)]
421pub struct TopicData {
422 pub topic_id: Uuid,
426
427 pub partitions: Vec<PartitionData>,
431
432 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
434}
435
436impl TopicData {
437 pub fn with_topic_id(mut self, value: Uuid) -> Self {
443 self.topic_id = value;
444 self
445 }
446 pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
452 self.partitions = value;
453 self
454 }
455 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
457 self.unknown_tagged_fields = value;
458 self
459 }
460 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
462 self.unknown_tagged_fields.insert(key, value);
463 self
464 }
465}
466
467#[cfg(feature = "broker")]
468impl Encodable for TopicData {
469 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
470 if version != 0 {
471 bail!("specified version not supported by this message type");
472 }
473 types::Uuid.encode(buf, &self.topic_id)?;
474 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
475 let num_tagged_fields = self.unknown_tagged_fields.len();
476 if num_tagged_fields > std::u32::MAX as usize {
477 bail!(
478 "Too many tagged fields to encode ({} fields)",
479 num_tagged_fields
480 );
481 }
482 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
483
484 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
485 Ok(())
486 }
487 fn compute_size(&self, version: i16) -> Result<usize> {
488 let mut total_size = 0;
489 total_size += types::Uuid.compute_size(&self.topic_id)?;
490 total_size +=
491 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
492 let num_tagged_fields = self.unknown_tagged_fields.len();
493 if num_tagged_fields > std::u32::MAX as usize {
494 bail!(
495 "Too many tagged fields to encode ({} fields)",
496 num_tagged_fields
497 );
498 }
499 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
500
501 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
502 Ok(total_size)
503 }
504}
505
506#[cfg(feature = "client")]
507impl Decodable for TopicData {
508 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
509 if version != 0 {
510 bail!("specified version not supported by this message type");
511 }
512 let topic_id = types::Uuid.decode(buf)?;
513 let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
514 let mut unknown_tagged_fields = BTreeMap::new();
515 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
516 for _ in 0..num_tagged_fields {
517 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
518 let size: u32 = types::UnsignedVarInt.decode(buf)?;
519 let unknown_value = buf.try_get_bytes(size as usize)?;
520 unknown_tagged_fields.insert(tag as i32, unknown_value);
521 }
522 Ok(Self {
523 topic_id,
524 partitions,
525 unknown_tagged_fields,
526 })
527 }
528}
529
530impl Default for TopicData {
531 fn default() -> Self {
532 Self {
533 topic_id: Uuid::nil(),
534 partitions: Default::default(),
535 unknown_tagged_fields: BTreeMap::new(),
536 }
537 }
538}
539
540impl Message for TopicData {
541 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
542 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
543}
544
545impl HeaderVersion for AssignReplicasToDirsResponse {
546 fn header_version(version: i16) -> i16 {
547 1
548 }
549}