kafka_protocol/messages/
assign_replicas_to_dirs_request.rs

1//! AssignReplicasToDirsRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/AssignReplicasToDirsRequest.json).
4// WARNING: the items of this module are generated and should not be edited directly
5#![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/// Valid versions: 0
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct AssignReplicasToDirsRequest {
24    /// The ID of the requesting broker
25    ///
26    /// Supported API versions: 0
27    pub broker_id: super::BrokerId,
28
29    /// The epoch of the requesting broker
30    ///
31    /// Supported API versions: 0
32    pub broker_epoch: i64,
33
34    ///
35    ///
36    /// Supported API versions: 0
37    pub directories: Vec<DirectoryData>,
38
39    /// Other tagged fields
40    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl AssignReplicasToDirsRequest {
44    /// Sets `broker_id` to the passed value.
45    ///
46    /// The ID of the requesting broker
47    ///
48    /// Supported API versions: 0
49    pub fn with_broker_id(mut self, value: super::BrokerId) -> Self {
50        self.broker_id = value;
51        self
52    }
53    /// Sets `broker_epoch` to the passed value.
54    ///
55    /// The epoch of the requesting broker
56    ///
57    /// Supported API versions: 0
58    pub fn with_broker_epoch(mut self, value: i64) -> Self {
59        self.broker_epoch = value;
60        self
61    }
62    /// Sets `directories` to the passed value.
63    ///
64    ///
65    ///
66    /// Supported API versions: 0
67    pub fn with_directories(mut self, value: Vec<DirectoryData>) -> Self {
68        self.directories = value;
69        self
70    }
71    /// Sets unknown_tagged_fields to the passed value.
72    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73        self.unknown_tagged_fields = value;
74        self
75    }
76    /// Inserts an entry into unknown_tagged_fields.
77    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 = "client")]
84impl Encodable for AssignReplicasToDirsRequest {
85    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86        types::Int32.encode(buf, &self.broker_id)?;
87        types::Int64.encode(buf, &self.broker_epoch)?;
88        types::CompactArray(types::Struct { version }).encode(buf, &self.directories)?;
89        let num_tagged_fields = self.unknown_tagged_fields.len();
90        if num_tagged_fields > std::u32::MAX as usize {
91            bail!(
92                "Too many tagged fields to encode ({} fields)",
93                num_tagged_fields
94            );
95        }
96        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
97
98        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
99        Ok(())
100    }
101    fn compute_size(&self, version: i16) -> Result<usize> {
102        let mut total_size = 0;
103        total_size += types::Int32.compute_size(&self.broker_id)?;
104        total_size += types::Int64.compute_size(&self.broker_epoch)?;
105        total_size +=
106            types::CompactArray(types::Struct { version }).compute_size(&self.directories)?;
107        let num_tagged_fields = self.unknown_tagged_fields.len();
108        if num_tagged_fields > std::u32::MAX as usize {
109            bail!(
110                "Too many tagged fields to encode ({} fields)",
111                num_tagged_fields
112            );
113        }
114        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
115
116        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
117        Ok(total_size)
118    }
119}
120
121#[cfg(feature = "broker")]
122impl Decodable for AssignReplicasToDirsRequest {
123    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
124        let broker_id = types::Int32.decode(buf)?;
125        let broker_epoch = types::Int64.decode(buf)?;
126        let directories = types::CompactArray(types::Struct { version }).decode(buf)?;
127        let mut unknown_tagged_fields = BTreeMap::new();
128        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
129        for _ in 0..num_tagged_fields {
130            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
131            let size: u32 = types::UnsignedVarInt.decode(buf)?;
132            let unknown_value = buf.try_get_bytes(size as usize)?;
133            unknown_tagged_fields.insert(tag as i32, unknown_value);
134        }
135        Ok(Self {
136            broker_id,
137            broker_epoch,
138            directories,
139            unknown_tagged_fields,
140        })
141    }
142}
143
144impl Default for AssignReplicasToDirsRequest {
145    fn default() -> Self {
146        Self {
147            broker_id: (0).into(),
148            broker_epoch: -1,
149            directories: Default::default(),
150            unknown_tagged_fields: BTreeMap::new(),
151        }
152    }
153}
154
155impl Message for AssignReplicasToDirsRequest {
156    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
157    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
158}
159
160/// Valid versions: 0
161#[non_exhaustive]
162#[derive(Debug, Clone, PartialEq)]
163pub struct DirectoryData {
164    /// The ID of the directory
165    ///
166    /// Supported API versions: 0
167    pub id: Uuid,
168
169    ///
170    ///
171    /// Supported API versions: 0
172    pub topics: Vec<TopicData>,
173
174    /// Other tagged fields
175    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
176}
177
178impl DirectoryData {
179    /// Sets `id` to the passed value.
180    ///
181    /// The ID of the directory
182    ///
183    /// Supported API versions: 0
184    pub fn with_id(mut self, value: Uuid) -> Self {
185        self.id = value;
186        self
187    }
188    /// Sets `topics` to the passed value.
189    ///
190    ///
191    ///
192    /// Supported API versions: 0
193    pub fn with_topics(mut self, value: Vec<TopicData>) -> Self {
194        self.topics = value;
195        self
196    }
197    /// Sets unknown_tagged_fields to the passed value.
198    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
199        self.unknown_tagged_fields = value;
200        self
201    }
202    /// Inserts an entry into unknown_tagged_fields.
203    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
204        self.unknown_tagged_fields.insert(key, value);
205        self
206    }
207}
208
209#[cfg(feature = "client")]
210impl Encodable for DirectoryData {
211    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
212        types::Uuid.encode(buf, &self.id)?;
213        types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?;
214        let num_tagged_fields = self.unknown_tagged_fields.len();
215        if num_tagged_fields > std::u32::MAX as usize {
216            bail!(
217                "Too many tagged fields to encode ({} fields)",
218                num_tagged_fields
219            );
220        }
221        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
222
223        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
224        Ok(())
225    }
226    fn compute_size(&self, version: i16) -> Result<usize> {
227        let mut total_size = 0;
228        total_size += types::Uuid.compute_size(&self.id)?;
229        total_size += types::CompactArray(types::Struct { version }).compute_size(&self.topics)?;
230        let num_tagged_fields = self.unknown_tagged_fields.len();
231        if num_tagged_fields > std::u32::MAX as usize {
232            bail!(
233                "Too many tagged fields to encode ({} fields)",
234                num_tagged_fields
235            );
236        }
237        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
238
239        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
240        Ok(total_size)
241    }
242}
243
244#[cfg(feature = "broker")]
245impl Decodable for DirectoryData {
246    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
247        let id = types::Uuid.decode(buf)?;
248        let topics = types::CompactArray(types::Struct { version }).decode(buf)?;
249        let mut unknown_tagged_fields = BTreeMap::new();
250        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
251        for _ in 0..num_tagged_fields {
252            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
253            let size: u32 = types::UnsignedVarInt.decode(buf)?;
254            let unknown_value = buf.try_get_bytes(size as usize)?;
255            unknown_tagged_fields.insert(tag as i32, unknown_value);
256        }
257        Ok(Self {
258            id,
259            topics,
260            unknown_tagged_fields,
261        })
262    }
263}
264
265impl Default for DirectoryData {
266    fn default() -> Self {
267        Self {
268            id: Uuid::nil(),
269            topics: Default::default(),
270            unknown_tagged_fields: BTreeMap::new(),
271        }
272    }
273}
274
275impl Message for DirectoryData {
276    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
277    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
278}
279
280/// Valid versions: 0
281#[non_exhaustive]
282#[derive(Debug, Clone, PartialEq)]
283pub struct PartitionData {
284    /// The partition index
285    ///
286    /// Supported API versions: 0
287    pub partition_index: i32,
288
289    /// Other tagged fields
290    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
291}
292
293impl PartitionData {
294    /// Sets `partition_index` to the passed value.
295    ///
296    /// The partition index
297    ///
298    /// Supported API versions: 0
299    pub fn with_partition_index(mut self, value: i32) -> Self {
300        self.partition_index = value;
301        self
302    }
303    /// Sets unknown_tagged_fields to the passed value.
304    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
305        self.unknown_tagged_fields = value;
306        self
307    }
308    /// Inserts an entry into unknown_tagged_fields.
309    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
310        self.unknown_tagged_fields.insert(key, value);
311        self
312    }
313}
314
315#[cfg(feature = "client")]
316impl Encodable for PartitionData {
317    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
318        types::Int32.encode(buf, &self.partition_index)?;
319        let num_tagged_fields = self.unknown_tagged_fields.len();
320        if num_tagged_fields > std::u32::MAX as usize {
321            bail!(
322                "Too many tagged fields to encode ({} fields)",
323                num_tagged_fields
324            );
325        }
326        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
327
328        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
329        Ok(())
330    }
331    fn compute_size(&self, version: i16) -> Result<usize> {
332        let mut total_size = 0;
333        total_size += types::Int32.compute_size(&self.partition_index)?;
334        let num_tagged_fields = self.unknown_tagged_fields.len();
335        if num_tagged_fields > std::u32::MAX as usize {
336            bail!(
337                "Too many tagged fields to encode ({} fields)",
338                num_tagged_fields
339            );
340        }
341        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
342
343        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
344        Ok(total_size)
345    }
346}
347
348#[cfg(feature = "broker")]
349impl Decodable for PartitionData {
350    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
351        let partition_index = types::Int32.decode(buf)?;
352        let mut unknown_tagged_fields = BTreeMap::new();
353        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
354        for _ in 0..num_tagged_fields {
355            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
356            let size: u32 = types::UnsignedVarInt.decode(buf)?;
357            let unknown_value = buf.try_get_bytes(size as usize)?;
358            unknown_tagged_fields.insert(tag as i32, unknown_value);
359        }
360        Ok(Self {
361            partition_index,
362            unknown_tagged_fields,
363        })
364    }
365}
366
367impl Default for PartitionData {
368    fn default() -> Self {
369        Self {
370            partition_index: 0,
371            unknown_tagged_fields: BTreeMap::new(),
372        }
373    }
374}
375
376impl Message for PartitionData {
377    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
378    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
379}
380
381/// Valid versions: 0
382#[non_exhaustive]
383#[derive(Debug, Clone, PartialEq)]
384pub struct TopicData {
385    /// The ID of the assigned topic
386    ///
387    /// Supported API versions: 0
388    pub topic_id: Uuid,
389
390    ///
391    ///
392    /// Supported API versions: 0
393    pub partitions: Vec<PartitionData>,
394
395    /// Other tagged fields
396    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
397}
398
399impl TopicData {
400    /// Sets `topic_id` to the passed value.
401    ///
402    /// The ID of the assigned topic
403    ///
404    /// Supported API versions: 0
405    pub fn with_topic_id(mut self, value: Uuid) -> Self {
406        self.topic_id = value;
407        self
408    }
409    /// Sets `partitions` to the passed value.
410    ///
411    ///
412    ///
413    /// Supported API versions: 0
414    pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
415        self.partitions = value;
416        self
417    }
418    /// Sets unknown_tagged_fields to the passed value.
419    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
420        self.unknown_tagged_fields = value;
421        self
422    }
423    /// Inserts an entry into unknown_tagged_fields.
424    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
425        self.unknown_tagged_fields.insert(key, value);
426        self
427    }
428}
429
430#[cfg(feature = "client")]
431impl Encodable for TopicData {
432    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
433        types::Uuid.encode(buf, &self.topic_id)?;
434        types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
435        let num_tagged_fields = self.unknown_tagged_fields.len();
436        if num_tagged_fields > std::u32::MAX as usize {
437            bail!(
438                "Too many tagged fields to encode ({} fields)",
439                num_tagged_fields
440            );
441        }
442        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
443
444        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
445        Ok(())
446    }
447    fn compute_size(&self, version: i16) -> Result<usize> {
448        let mut total_size = 0;
449        total_size += types::Uuid.compute_size(&self.topic_id)?;
450        total_size +=
451            types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
452        let num_tagged_fields = self.unknown_tagged_fields.len();
453        if num_tagged_fields > std::u32::MAX as usize {
454            bail!(
455                "Too many tagged fields to encode ({} fields)",
456                num_tagged_fields
457            );
458        }
459        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
460
461        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
462        Ok(total_size)
463    }
464}
465
466#[cfg(feature = "broker")]
467impl Decodable for TopicData {
468    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
469        let topic_id = types::Uuid.decode(buf)?;
470        let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
471        let mut unknown_tagged_fields = BTreeMap::new();
472        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
473        for _ in 0..num_tagged_fields {
474            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
475            let size: u32 = types::UnsignedVarInt.decode(buf)?;
476            let unknown_value = buf.try_get_bytes(size as usize)?;
477            unknown_tagged_fields.insert(tag as i32, unknown_value);
478        }
479        Ok(Self {
480            topic_id,
481            partitions,
482            unknown_tagged_fields,
483        })
484    }
485}
486
487impl Default for TopicData {
488    fn default() -> Self {
489        Self {
490            topic_id: Uuid::nil(),
491            partitions: Default::default(),
492            unknown_tagged_fields: BTreeMap::new(),
493        }
494    }
495}
496
497impl Message for TopicData {
498    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
499    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
500}
501
502impl HeaderVersion for AssignReplicasToDirsRequest {
503    fn header_version(version: i16) -> i16 {
504        2
505    }
506}