kafka_protocol/messages/
alter_replica_log_dirs_response.rs

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