kafka_protocol/messages/
incremental_alter_configs_request.rs

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