Skip to main content

kafka_protocol/messages/
describe_configs_response.rs

1//! DescribeConfigsResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/DescribeConfigsResponse.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-4
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct DescribeConfigsResourceResult {
24    /// The configuration name.
25    ///
26    /// Supported API versions: 1-4
27    pub name: StrBytes,
28
29    /// The configuration value.
30    ///
31    /// Supported API versions: 1-4
32    pub value: Option<StrBytes>,
33
34    /// True if the configuration is read-only.
35    ///
36    /// Supported API versions: 1-4
37    pub read_only: bool,
38
39    /// The configuration source.
40    ///
41    /// Supported API versions: 1-4
42    pub config_source: i8,
43
44    /// True if this configuration is sensitive.
45    ///
46    /// Supported API versions: 1-4
47    pub is_sensitive: bool,
48
49    /// The synonyms for this configuration key.
50    ///
51    /// Supported API versions: 1-4
52    pub synonyms: Vec<DescribeConfigsSynonym>,
53
54    /// The configuration data type. Type can be one of the following values - BOOLEAN, STRING, INT, SHORT, LONG, DOUBLE, LIST, CLASS, PASSWORD.
55    ///
56    /// Supported API versions: 3-4
57    pub config_type: i8,
58
59    /// The configuration documentation.
60    ///
61    /// Supported API versions: 3-4
62    pub documentation: Option<StrBytes>,
63
64    /// Other tagged fields
65    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
66}
67
68impl DescribeConfigsResourceResult {
69    /// Sets `name` to the passed value.
70    ///
71    /// The configuration name.
72    ///
73    /// Supported API versions: 1-4
74    pub fn with_name(mut self, value: StrBytes) -> Self {
75        self.name = value;
76        self
77    }
78    /// Sets `value` to the passed value.
79    ///
80    /// The configuration value.
81    ///
82    /// Supported API versions: 1-4
83    pub fn with_value(mut self, value: Option<StrBytes>) -> Self {
84        self.value = value;
85        self
86    }
87    /// Sets `read_only` to the passed value.
88    ///
89    /// True if the configuration is read-only.
90    ///
91    /// Supported API versions: 1-4
92    pub fn with_read_only(mut self, value: bool) -> Self {
93        self.read_only = value;
94        self
95    }
96    /// Sets `config_source` to the passed value.
97    ///
98    /// The configuration source.
99    ///
100    /// Supported API versions: 1-4
101    pub fn with_config_source(mut self, value: i8) -> Self {
102        self.config_source = value;
103        self
104    }
105    /// Sets `is_sensitive` to the passed value.
106    ///
107    /// True if this configuration is sensitive.
108    ///
109    /// Supported API versions: 1-4
110    pub fn with_is_sensitive(mut self, value: bool) -> Self {
111        self.is_sensitive = value;
112        self
113    }
114    /// Sets `synonyms` to the passed value.
115    ///
116    /// The synonyms for this configuration key.
117    ///
118    /// Supported API versions: 1-4
119    pub fn with_synonyms(mut self, value: Vec<DescribeConfigsSynonym>) -> Self {
120        self.synonyms = value;
121        self
122    }
123    /// Sets `config_type` to the passed value.
124    ///
125    /// The configuration data type. Type can be one of the following values - BOOLEAN, STRING, INT, SHORT, LONG, DOUBLE, LIST, CLASS, PASSWORD.
126    ///
127    /// Supported API versions: 3-4
128    pub fn with_config_type(mut self, value: i8) -> Self {
129        self.config_type = value;
130        self
131    }
132    /// Sets `documentation` to the passed value.
133    ///
134    /// The configuration documentation.
135    ///
136    /// Supported API versions: 3-4
137    pub fn with_documentation(mut self, value: Option<StrBytes>) -> Self {
138        self.documentation = value;
139        self
140    }
141    /// Sets unknown_tagged_fields to the passed value.
142    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
143        self.unknown_tagged_fields = value;
144        self
145    }
146    /// Inserts an entry into unknown_tagged_fields.
147    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
148        self.unknown_tagged_fields.insert(key, value);
149        self
150    }
151}
152
153#[cfg(feature = "broker")]
154impl Encodable for DescribeConfigsResourceResult {
155    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
156        if version < 1 || version > 4 {
157            bail!("specified version not supported by this message type");
158        }
159        if version >= 4 {
160            types::CompactString.encode(buf, &self.name)?;
161        } else {
162            types::String.encode(buf, &self.name)?;
163        }
164        if version >= 4 {
165            types::CompactString.encode(buf, &self.value)?;
166        } else {
167            types::String.encode(buf, &self.value)?;
168        }
169        types::Boolean.encode(buf, &self.read_only)?;
170        types::Int8.encode(buf, &self.config_source)?;
171        types::Boolean.encode(buf, &self.is_sensitive)?;
172        if version >= 4 {
173            types::CompactArray(types::Struct { version }).encode(buf, &self.synonyms)?;
174        } else {
175            types::Array(types::Struct { version }).encode(buf, &self.synonyms)?;
176        }
177        if version >= 3 {
178            types::Int8.encode(buf, &self.config_type)?;
179        }
180        if version >= 3 {
181            if version >= 4 {
182                types::CompactString.encode(buf, &self.documentation)?;
183            } else {
184                types::String.encode(buf, &self.documentation)?;
185            }
186        }
187        if version >= 4 {
188            let num_tagged_fields = self.unknown_tagged_fields.len();
189            if num_tagged_fields > std::u32::MAX as usize {
190                bail!(
191                    "Too many tagged fields to encode ({} fields)",
192                    num_tagged_fields
193                );
194            }
195            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
196
197            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
198        }
199        Ok(())
200    }
201    fn compute_size(&self, version: i16) -> Result<usize> {
202        let mut total_size = 0;
203        if version >= 4 {
204            total_size += types::CompactString.compute_size(&self.name)?;
205        } else {
206            total_size += types::String.compute_size(&self.name)?;
207        }
208        if version >= 4 {
209            total_size += types::CompactString.compute_size(&self.value)?;
210        } else {
211            total_size += types::String.compute_size(&self.value)?;
212        }
213        total_size += types::Boolean.compute_size(&self.read_only)?;
214        total_size += types::Int8.compute_size(&self.config_source)?;
215        total_size += types::Boolean.compute_size(&self.is_sensitive)?;
216        if version >= 4 {
217            total_size +=
218                types::CompactArray(types::Struct { version }).compute_size(&self.synonyms)?;
219        } else {
220            total_size += types::Array(types::Struct { version }).compute_size(&self.synonyms)?;
221        }
222        if version >= 3 {
223            total_size += types::Int8.compute_size(&self.config_type)?;
224        }
225        if version >= 3 {
226            if version >= 4 {
227                total_size += types::CompactString.compute_size(&self.documentation)?;
228            } else {
229                total_size += types::String.compute_size(&self.documentation)?;
230            }
231        }
232        if version >= 4 {
233            let num_tagged_fields = self.unknown_tagged_fields.len();
234            if num_tagged_fields > std::u32::MAX as usize {
235                bail!(
236                    "Too many tagged fields to encode ({} fields)",
237                    num_tagged_fields
238                );
239            }
240            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
241
242            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
243        }
244        Ok(total_size)
245    }
246}
247
248#[cfg(feature = "client")]
249impl Decodable for DescribeConfigsResourceResult {
250    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
251        if version < 1 || version > 4 {
252            bail!("specified version not supported by this message type");
253        }
254        let name = if version >= 4 {
255            types::CompactString.decode(buf)?
256        } else {
257            types::String.decode(buf)?
258        };
259        let value = if version >= 4 {
260            types::CompactString.decode(buf)?
261        } else {
262            types::String.decode(buf)?
263        };
264        let read_only = types::Boolean.decode(buf)?;
265        let config_source = types::Int8.decode(buf)?;
266        let is_sensitive = types::Boolean.decode(buf)?;
267        let synonyms = if version >= 4 {
268            types::CompactArray(types::Struct { version }).decode(buf)?
269        } else {
270            types::Array(types::Struct { version }).decode(buf)?
271        };
272        let config_type = if version >= 3 {
273            types::Int8.decode(buf)?
274        } else {
275            0
276        };
277        let documentation = if version >= 3 {
278            if version >= 4 {
279                types::CompactString.decode(buf)?
280            } else {
281                types::String.decode(buf)?
282            }
283        } else {
284            Some(Default::default())
285        };
286        let mut unknown_tagged_fields = BTreeMap::new();
287        if version >= 4 {
288            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
289            for _ in 0..num_tagged_fields {
290                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
291                let size: u32 = types::UnsignedVarInt.decode(buf)?;
292                let unknown_value = buf.try_get_bytes(size as usize)?;
293                unknown_tagged_fields.insert(tag as i32, unknown_value);
294            }
295        }
296        Ok(Self {
297            name,
298            value,
299            read_only,
300            config_source,
301            is_sensitive,
302            synonyms,
303            config_type,
304            documentation,
305            unknown_tagged_fields,
306        })
307    }
308}
309
310impl Default for DescribeConfigsResourceResult {
311    fn default() -> Self {
312        Self {
313            name: Default::default(),
314            value: Some(Default::default()),
315            read_only: false,
316            config_source: -1,
317            is_sensitive: false,
318            synonyms: Default::default(),
319            config_type: 0,
320            documentation: Some(Default::default()),
321            unknown_tagged_fields: BTreeMap::new(),
322        }
323    }
324}
325
326impl Message for DescribeConfigsResourceResult {
327    const VERSIONS: VersionRange = VersionRange { min: 1, max: 4 };
328    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
329}
330
331/// Valid versions: 1-4
332#[non_exhaustive]
333#[derive(Debug, Clone, PartialEq)]
334pub struct DescribeConfigsResponse {
335    /// 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.
336    ///
337    /// Supported API versions: 1-4
338    pub throttle_time_ms: i32,
339
340    /// The results for each resource.
341    ///
342    /// Supported API versions: 1-4
343    pub results: Vec<DescribeConfigsResult>,
344
345    /// Other tagged fields
346    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
347}
348
349impl DescribeConfigsResponse {
350    /// Sets `throttle_time_ms` to the passed value.
351    ///
352    /// 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.
353    ///
354    /// Supported API versions: 1-4
355    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
356        self.throttle_time_ms = value;
357        self
358    }
359    /// Sets `results` to the passed value.
360    ///
361    /// The results for each resource.
362    ///
363    /// Supported API versions: 1-4
364    pub fn with_results(mut self, value: Vec<DescribeConfigsResult>) -> Self {
365        self.results = value;
366        self
367    }
368    /// Sets unknown_tagged_fields to the passed value.
369    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
370        self.unknown_tagged_fields = value;
371        self
372    }
373    /// Inserts an entry into unknown_tagged_fields.
374    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
375        self.unknown_tagged_fields.insert(key, value);
376        self
377    }
378}
379
380#[cfg(feature = "broker")]
381impl Encodable for DescribeConfigsResponse {
382    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
383        if version < 1 || version > 4 {
384            bail!("specified version not supported by this message type");
385        }
386        types::Int32.encode(buf, &self.throttle_time_ms)?;
387        if version >= 4 {
388            types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
389        } else {
390            types::Array(types::Struct { version }).encode(buf, &self.results)?;
391        }
392        if version >= 4 {
393            let num_tagged_fields = self.unknown_tagged_fields.len();
394            if num_tagged_fields > std::u32::MAX as usize {
395                bail!(
396                    "Too many tagged fields to encode ({} fields)",
397                    num_tagged_fields
398                );
399            }
400            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
401
402            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
403        }
404        Ok(())
405    }
406    fn compute_size(&self, version: i16) -> Result<usize> {
407        let mut total_size = 0;
408        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
409        if version >= 4 {
410            total_size +=
411                types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
412        } else {
413            total_size += types::Array(types::Struct { version }).compute_size(&self.results)?;
414        }
415        if version >= 4 {
416            let num_tagged_fields = self.unknown_tagged_fields.len();
417            if num_tagged_fields > std::u32::MAX as usize {
418                bail!(
419                    "Too many tagged fields to encode ({} fields)",
420                    num_tagged_fields
421                );
422            }
423            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
424
425            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
426        }
427        Ok(total_size)
428    }
429}
430
431#[cfg(feature = "client")]
432impl Decodable for DescribeConfigsResponse {
433    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
434        if version < 1 || version > 4 {
435            bail!("specified version not supported by this message type");
436        }
437        let throttle_time_ms = types::Int32.decode(buf)?;
438        let results = if version >= 4 {
439            types::CompactArray(types::Struct { version }).decode(buf)?
440        } else {
441            types::Array(types::Struct { version }).decode(buf)?
442        };
443        let mut unknown_tagged_fields = BTreeMap::new();
444        if version >= 4 {
445            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
446            for _ in 0..num_tagged_fields {
447                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
448                let size: u32 = types::UnsignedVarInt.decode(buf)?;
449                let unknown_value = buf.try_get_bytes(size as usize)?;
450                unknown_tagged_fields.insert(tag as i32, unknown_value);
451            }
452        }
453        Ok(Self {
454            throttle_time_ms,
455            results,
456            unknown_tagged_fields,
457        })
458    }
459}
460
461impl Default for DescribeConfigsResponse {
462    fn default() -> Self {
463        Self {
464            throttle_time_ms: 0,
465            results: Default::default(),
466            unknown_tagged_fields: BTreeMap::new(),
467        }
468    }
469}
470
471impl Message for DescribeConfigsResponse {
472    const VERSIONS: VersionRange = VersionRange { min: 1, max: 4 };
473    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
474}
475
476/// Valid versions: 1-4
477#[non_exhaustive]
478#[derive(Debug, Clone, PartialEq)]
479pub struct DescribeConfigsResult {
480    /// The error code, or 0 if we were able to successfully describe the configurations.
481    ///
482    /// Supported API versions: 1-4
483    pub error_code: i16,
484
485    /// The error message, or null if we were able to successfully describe the configurations.
486    ///
487    /// Supported API versions: 1-4
488    pub error_message: Option<StrBytes>,
489
490    /// The resource type.
491    ///
492    /// Supported API versions: 1-4
493    pub resource_type: i8,
494
495    /// The resource name.
496    ///
497    /// Supported API versions: 1-4
498    pub resource_name: StrBytes,
499
500    /// Each listed configuration.
501    ///
502    /// Supported API versions: 1-4
503    pub configs: Vec<DescribeConfigsResourceResult>,
504
505    /// Other tagged fields
506    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
507}
508
509impl DescribeConfigsResult {
510    /// Sets `error_code` to the passed value.
511    ///
512    /// The error code, or 0 if we were able to successfully describe the configurations.
513    ///
514    /// Supported API versions: 1-4
515    pub fn with_error_code(mut self, value: i16) -> Self {
516        self.error_code = value;
517        self
518    }
519    /// Sets `error_message` to the passed value.
520    ///
521    /// The error message, or null if we were able to successfully describe the configurations.
522    ///
523    /// Supported API versions: 1-4
524    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
525        self.error_message = value;
526        self
527    }
528    /// Sets `resource_type` to the passed value.
529    ///
530    /// The resource type.
531    ///
532    /// Supported API versions: 1-4
533    pub fn with_resource_type(mut self, value: i8) -> Self {
534        self.resource_type = value;
535        self
536    }
537    /// Sets `resource_name` to the passed value.
538    ///
539    /// The resource name.
540    ///
541    /// Supported API versions: 1-4
542    pub fn with_resource_name(mut self, value: StrBytes) -> Self {
543        self.resource_name = value;
544        self
545    }
546    /// Sets `configs` to the passed value.
547    ///
548    /// Each listed configuration.
549    ///
550    /// Supported API versions: 1-4
551    pub fn with_configs(mut self, value: Vec<DescribeConfigsResourceResult>) -> Self {
552        self.configs = value;
553        self
554    }
555    /// Sets unknown_tagged_fields to the passed value.
556    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
557        self.unknown_tagged_fields = value;
558        self
559    }
560    /// Inserts an entry into unknown_tagged_fields.
561    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
562        self.unknown_tagged_fields.insert(key, value);
563        self
564    }
565}
566
567#[cfg(feature = "broker")]
568impl Encodable for DescribeConfigsResult {
569    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
570        if version < 1 || version > 4 {
571            bail!("specified version not supported by this message type");
572        }
573        types::Int16.encode(buf, &self.error_code)?;
574        if version >= 4 {
575            types::CompactString.encode(buf, &self.error_message)?;
576        } else {
577            types::String.encode(buf, &self.error_message)?;
578        }
579        types::Int8.encode(buf, &self.resource_type)?;
580        if version >= 4 {
581            types::CompactString.encode(buf, &self.resource_name)?;
582        } else {
583            types::String.encode(buf, &self.resource_name)?;
584        }
585        if version >= 4 {
586            types::CompactArray(types::Struct { version }).encode(buf, &self.configs)?;
587        } else {
588            types::Array(types::Struct { version }).encode(buf, &self.configs)?;
589        }
590        if version >= 4 {
591            let num_tagged_fields = self.unknown_tagged_fields.len();
592            if num_tagged_fields > std::u32::MAX as usize {
593                bail!(
594                    "Too many tagged fields to encode ({} fields)",
595                    num_tagged_fields
596                );
597            }
598            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
599
600            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
601        }
602        Ok(())
603    }
604    fn compute_size(&self, version: i16) -> Result<usize> {
605        let mut total_size = 0;
606        total_size += types::Int16.compute_size(&self.error_code)?;
607        if version >= 4 {
608            total_size += types::CompactString.compute_size(&self.error_message)?;
609        } else {
610            total_size += types::String.compute_size(&self.error_message)?;
611        }
612        total_size += types::Int8.compute_size(&self.resource_type)?;
613        if version >= 4 {
614            total_size += types::CompactString.compute_size(&self.resource_name)?;
615        } else {
616            total_size += types::String.compute_size(&self.resource_name)?;
617        }
618        if version >= 4 {
619            total_size +=
620                types::CompactArray(types::Struct { version }).compute_size(&self.configs)?;
621        } else {
622            total_size += types::Array(types::Struct { version }).compute_size(&self.configs)?;
623        }
624        if version >= 4 {
625            let num_tagged_fields = self.unknown_tagged_fields.len();
626            if num_tagged_fields > std::u32::MAX as usize {
627                bail!(
628                    "Too many tagged fields to encode ({} fields)",
629                    num_tagged_fields
630                );
631            }
632            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
633
634            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
635        }
636        Ok(total_size)
637    }
638}
639
640#[cfg(feature = "client")]
641impl Decodable for DescribeConfigsResult {
642    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
643        if version < 1 || version > 4 {
644            bail!("specified version not supported by this message type");
645        }
646        let error_code = types::Int16.decode(buf)?;
647        let error_message = if version >= 4 {
648            types::CompactString.decode(buf)?
649        } else {
650            types::String.decode(buf)?
651        };
652        let resource_type = types::Int8.decode(buf)?;
653        let resource_name = if version >= 4 {
654            types::CompactString.decode(buf)?
655        } else {
656            types::String.decode(buf)?
657        };
658        let configs = if version >= 4 {
659            types::CompactArray(types::Struct { version }).decode(buf)?
660        } else {
661            types::Array(types::Struct { version }).decode(buf)?
662        };
663        let mut unknown_tagged_fields = BTreeMap::new();
664        if version >= 4 {
665            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
666            for _ in 0..num_tagged_fields {
667                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
668                let size: u32 = types::UnsignedVarInt.decode(buf)?;
669                let unknown_value = buf.try_get_bytes(size as usize)?;
670                unknown_tagged_fields.insert(tag as i32, unknown_value);
671            }
672        }
673        Ok(Self {
674            error_code,
675            error_message,
676            resource_type,
677            resource_name,
678            configs,
679            unknown_tagged_fields,
680        })
681    }
682}
683
684impl Default for DescribeConfigsResult {
685    fn default() -> Self {
686        Self {
687            error_code: 0,
688            error_message: Some(Default::default()),
689            resource_type: 0,
690            resource_name: Default::default(),
691            configs: Default::default(),
692            unknown_tagged_fields: BTreeMap::new(),
693        }
694    }
695}
696
697impl Message for DescribeConfigsResult {
698    const VERSIONS: VersionRange = VersionRange { min: 1, max: 4 };
699    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
700}
701
702/// Valid versions: 1-4
703#[non_exhaustive]
704#[derive(Debug, Clone, PartialEq)]
705pub struct DescribeConfigsSynonym {
706    /// The synonym name.
707    ///
708    /// Supported API versions: 1-4
709    pub name: StrBytes,
710
711    /// The synonym value.
712    ///
713    /// Supported API versions: 1-4
714    pub value: Option<StrBytes>,
715
716    /// The synonym source.
717    ///
718    /// Supported API versions: 1-4
719    pub source: i8,
720
721    /// Other tagged fields
722    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
723}
724
725impl DescribeConfigsSynonym {
726    /// Sets `name` to the passed value.
727    ///
728    /// The synonym name.
729    ///
730    /// Supported API versions: 1-4
731    pub fn with_name(mut self, value: StrBytes) -> Self {
732        self.name = value;
733        self
734    }
735    /// Sets `value` to the passed value.
736    ///
737    /// The synonym value.
738    ///
739    /// Supported API versions: 1-4
740    pub fn with_value(mut self, value: Option<StrBytes>) -> Self {
741        self.value = value;
742        self
743    }
744    /// Sets `source` to the passed value.
745    ///
746    /// The synonym source.
747    ///
748    /// Supported API versions: 1-4
749    pub fn with_source(mut self, value: i8) -> Self {
750        self.source = value;
751        self
752    }
753    /// Sets unknown_tagged_fields to the passed value.
754    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
755        self.unknown_tagged_fields = value;
756        self
757    }
758    /// Inserts an entry into unknown_tagged_fields.
759    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
760        self.unknown_tagged_fields.insert(key, value);
761        self
762    }
763}
764
765#[cfg(feature = "broker")]
766impl Encodable for DescribeConfigsSynonym {
767    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
768        if version < 1 || version > 4 {
769            bail!("specified version not supported by this message type");
770        }
771        if version >= 4 {
772            types::CompactString.encode(buf, &self.name)?;
773        } else {
774            types::String.encode(buf, &self.name)?;
775        }
776        if version >= 4 {
777            types::CompactString.encode(buf, &self.value)?;
778        } else {
779            types::String.encode(buf, &self.value)?;
780        }
781        types::Int8.encode(buf, &self.source)?;
782        if version >= 4 {
783            let num_tagged_fields = self.unknown_tagged_fields.len();
784            if num_tagged_fields > std::u32::MAX as usize {
785                bail!(
786                    "Too many tagged fields to encode ({} fields)",
787                    num_tagged_fields
788                );
789            }
790            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
791
792            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
793        }
794        Ok(())
795    }
796    fn compute_size(&self, version: i16) -> Result<usize> {
797        let mut total_size = 0;
798        if version >= 4 {
799            total_size += types::CompactString.compute_size(&self.name)?;
800        } else {
801            total_size += types::String.compute_size(&self.name)?;
802        }
803        if version >= 4 {
804            total_size += types::CompactString.compute_size(&self.value)?;
805        } else {
806            total_size += types::String.compute_size(&self.value)?;
807        }
808        total_size += types::Int8.compute_size(&self.source)?;
809        if version >= 4 {
810            let num_tagged_fields = self.unknown_tagged_fields.len();
811            if num_tagged_fields > std::u32::MAX as usize {
812                bail!(
813                    "Too many tagged fields to encode ({} fields)",
814                    num_tagged_fields
815                );
816            }
817            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
818
819            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
820        }
821        Ok(total_size)
822    }
823}
824
825#[cfg(feature = "client")]
826impl Decodable for DescribeConfigsSynonym {
827    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
828        if version < 1 || version > 4 {
829            bail!("specified version not supported by this message type");
830        }
831        let name = if version >= 4 {
832            types::CompactString.decode(buf)?
833        } else {
834            types::String.decode(buf)?
835        };
836        let value = if version >= 4 {
837            types::CompactString.decode(buf)?
838        } else {
839            types::String.decode(buf)?
840        };
841        let source = types::Int8.decode(buf)?;
842        let mut unknown_tagged_fields = BTreeMap::new();
843        if version >= 4 {
844            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
845            for _ in 0..num_tagged_fields {
846                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
847                let size: u32 = types::UnsignedVarInt.decode(buf)?;
848                let unknown_value = buf.try_get_bytes(size as usize)?;
849                unknown_tagged_fields.insert(tag as i32, unknown_value);
850            }
851        }
852        Ok(Self {
853            name,
854            value,
855            source,
856            unknown_tagged_fields,
857        })
858    }
859}
860
861impl Default for DescribeConfigsSynonym {
862    fn default() -> Self {
863        Self {
864            name: Default::default(),
865            value: Some(Default::default()),
866            source: 0,
867            unknown_tagged_fields: BTreeMap::new(),
868        }
869    }
870}
871
872impl Message for DescribeConfigsSynonym {
873    const VERSIONS: VersionRange = VersionRange { min: 1, max: 4 };
874    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
875}
876
877impl HeaderVersion for DescribeConfigsResponse {
878    fn header_version(version: i16) -> i16 {
879        if version >= 4 {
880            1
881        } else {
882            0
883        }
884    }
885}