kafka_protocol/messages/
alter_replica_log_dirs_request.rs

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