kafka_protocol/messages/
assign_replicas_to_dirs_response.rs

1//! AssignReplicasToDirsResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/AssignReplicasToDirsResponse.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 AssignReplicasToDirsResponse {
24    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
25    ///
26    /// Supported API versions: 0
27    pub throttle_time_ms: i32,
28
29    /// The top level response error code
30    ///
31    /// Supported API versions: 0
32    pub error_code: i16,
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 AssignReplicasToDirsResponse {
44    /// Sets `throttle_time_ms` to the passed value.
45    ///
46    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
47    ///
48    /// Supported API versions: 0
49    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
50        self.throttle_time_ms = value;
51        self
52    }
53    /// Sets `error_code` to the passed value.
54    ///
55    /// The top level response error code
56    ///
57    /// Supported API versions: 0
58    pub fn with_error_code(mut self, value: i16) -> Self {
59        self.error_code = 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 = "broker")]
84impl Encodable for AssignReplicasToDirsResponse {
85    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86        types::Int32.encode(buf, &self.throttle_time_ms)?;
87        types::Int16.encode(buf, &self.error_code)?;
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.throttle_time_ms)?;
104        total_size += types::Int16.compute_size(&self.error_code)?;
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 = "client")]
122impl Decodable for AssignReplicasToDirsResponse {
123    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
124        let throttle_time_ms = types::Int32.decode(buf)?;
125        let error_code = types::Int16.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            throttle_time_ms,
137            error_code,
138            directories,
139            unknown_tagged_fields,
140        })
141    }
142}
143
144impl Default for AssignReplicasToDirsResponse {
145    fn default() -> Self {
146        Self {
147            throttle_time_ms: 0,
148            error_code: 0,
149            directories: Default::default(),
150            unknown_tagged_fields: BTreeMap::new(),
151        }
152    }
153}
154
155impl Message for AssignReplicasToDirsResponse {
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 = "broker")]
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 = "client")]
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    /// The partition level error code
290    ///
291    /// Supported API versions: 0
292    pub error_code: i16,
293
294    /// Other tagged fields
295    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
296}
297
298impl PartitionData {
299    /// Sets `partition_index` to the passed value.
300    ///
301    /// The partition index
302    ///
303    /// Supported API versions: 0
304    pub fn with_partition_index(mut self, value: i32) -> Self {
305        self.partition_index = value;
306        self
307    }
308    /// Sets `error_code` to the passed value.
309    ///
310    /// The partition level error code
311    ///
312    /// Supported API versions: 0
313    pub fn with_error_code(mut self, value: i16) -> Self {
314        self.error_code = value;
315        self
316    }
317    /// Sets unknown_tagged_fields to the passed value.
318    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
319        self.unknown_tagged_fields = value;
320        self
321    }
322    /// Inserts an entry into unknown_tagged_fields.
323    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
324        self.unknown_tagged_fields.insert(key, value);
325        self
326    }
327}
328
329#[cfg(feature = "broker")]
330impl Encodable for PartitionData {
331    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
332        types::Int32.encode(buf, &self.partition_index)?;
333        types::Int16.encode(buf, &self.error_code)?;
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        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
342
343        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
344        Ok(())
345    }
346    fn compute_size(&self, version: i16) -> Result<usize> {
347        let mut total_size = 0;
348        total_size += types::Int32.compute_size(&self.partition_index)?;
349        total_size += types::Int16.compute_size(&self.error_code)?;
350        let num_tagged_fields = self.unknown_tagged_fields.len();
351        if num_tagged_fields > std::u32::MAX as usize {
352            bail!(
353                "Too many tagged fields to encode ({} fields)",
354                num_tagged_fields
355            );
356        }
357        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
358
359        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
360        Ok(total_size)
361    }
362}
363
364#[cfg(feature = "client")]
365impl Decodable for PartitionData {
366    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
367        let partition_index = types::Int32.decode(buf)?;
368        let error_code = types::Int16.decode(buf)?;
369        let mut unknown_tagged_fields = BTreeMap::new();
370        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
371        for _ in 0..num_tagged_fields {
372            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
373            let size: u32 = types::UnsignedVarInt.decode(buf)?;
374            let unknown_value = buf.try_get_bytes(size as usize)?;
375            unknown_tagged_fields.insert(tag as i32, unknown_value);
376        }
377        Ok(Self {
378            partition_index,
379            error_code,
380            unknown_tagged_fields,
381        })
382    }
383}
384
385impl Default for PartitionData {
386    fn default() -> Self {
387        Self {
388            partition_index: 0,
389            error_code: 0,
390            unknown_tagged_fields: BTreeMap::new(),
391        }
392    }
393}
394
395impl Message for PartitionData {
396    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
397    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
398}
399
400/// Valid versions: 0
401#[non_exhaustive]
402#[derive(Debug, Clone, PartialEq)]
403pub struct TopicData {
404    /// The ID of the assigned topic
405    ///
406    /// Supported API versions: 0
407    pub topic_id: Uuid,
408
409    ///
410    ///
411    /// Supported API versions: 0
412    pub partitions: Vec<PartitionData>,
413
414    /// Other tagged fields
415    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
416}
417
418impl TopicData {
419    /// Sets `topic_id` to the passed value.
420    ///
421    /// The ID of the assigned topic
422    ///
423    /// Supported API versions: 0
424    pub fn with_topic_id(mut self, value: Uuid) -> Self {
425        self.topic_id = value;
426        self
427    }
428    /// Sets `partitions` to the passed value.
429    ///
430    ///
431    ///
432    /// Supported API versions: 0
433    pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
434        self.partitions = value;
435        self
436    }
437    /// Sets unknown_tagged_fields to the passed value.
438    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
439        self.unknown_tagged_fields = value;
440        self
441    }
442    /// Inserts an entry into unknown_tagged_fields.
443    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
444        self.unknown_tagged_fields.insert(key, value);
445        self
446    }
447}
448
449#[cfg(feature = "broker")]
450impl Encodable for TopicData {
451    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
452        types::Uuid.encode(buf, &self.topic_id)?;
453        types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
454        let num_tagged_fields = self.unknown_tagged_fields.len();
455        if num_tagged_fields > std::u32::MAX as usize {
456            bail!(
457                "Too many tagged fields to encode ({} fields)",
458                num_tagged_fields
459            );
460        }
461        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
462
463        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
464        Ok(())
465    }
466    fn compute_size(&self, version: i16) -> Result<usize> {
467        let mut total_size = 0;
468        total_size += types::Uuid.compute_size(&self.topic_id)?;
469        total_size +=
470            types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
471        let num_tagged_fields = self.unknown_tagged_fields.len();
472        if num_tagged_fields > std::u32::MAX as usize {
473            bail!(
474                "Too many tagged fields to encode ({} fields)",
475                num_tagged_fields
476            );
477        }
478        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
479
480        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
481        Ok(total_size)
482    }
483}
484
485#[cfg(feature = "client")]
486impl Decodable for TopicData {
487    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
488        let topic_id = types::Uuid.decode(buf)?;
489        let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
490        let mut unknown_tagged_fields = BTreeMap::new();
491        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
492        for _ in 0..num_tagged_fields {
493            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
494            let size: u32 = types::UnsignedVarInt.decode(buf)?;
495            let unknown_value = buf.try_get_bytes(size as usize)?;
496            unknown_tagged_fields.insert(tag as i32, unknown_value);
497        }
498        Ok(Self {
499            topic_id,
500            partitions,
501            unknown_tagged_fields,
502        })
503    }
504}
505
506impl Default for TopicData {
507    fn default() -> Self {
508        Self {
509            topic_id: Uuid::nil(),
510            partitions: Default::default(),
511            unknown_tagged_fields: BTreeMap::new(),
512        }
513    }
514}
515
516impl Message for TopicData {
517    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
518    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
519}
520
521impl HeaderVersion for AssignReplicasToDirsResponse {
522    fn header_version(version: i16) -> i16 {
523        1
524    }
525}