kafka_protocol/messages/
list_config_resources_request.rs

1//! ListConfigResourcesRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/ListConfigResourcesRequest.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 ListConfigResourcesRequest {
24    /// The list of resource type. If the list is empty, it uses default supported config resource types.
25    ///
26    /// Supported API versions: 1
27    pub resource_types: Vec<i8>,
28
29    /// Other tagged fields
30    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
31}
32
33impl ListConfigResourcesRequest {
34    /// Sets `resource_types` to the passed value.
35    ///
36    /// The list of resource type. If the list is empty, it uses default supported config resource types.
37    ///
38    /// Supported API versions: 1
39    pub fn with_resource_types(mut self, value: Vec<i8>) -> Self {
40        self.resource_types = value;
41        self
42    }
43    /// Sets unknown_tagged_fields to the passed value.
44    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
45        self.unknown_tagged_fields = value;
46        self
47    }
48    /// Inserts an entry into unknown_tagged_fields.
49    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
50        self.unknown_tagged_fields.insert(key, value);
51        self
52    }
53}
54
55#[cfg(feature = "client")]
56impl Encodable for ListConfigResourcesRequest {
57    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
58        if version < 0 || version > 1 {
59            bail!("specified version not supported by this message type");
60        }
61        if version >= 1 {
62            types::CompactArray(types::Int8).encode(buf, &self.resource_types)?;
63        } else {
64            if !self.resource_types.is_empty() {
65                bail!("A field is set that is not available on the selected protocol version");
66            }
67        }
68        let num_tagged_fields = self.unknown_tagged_fields.len();
69        if num_tagged_fields > std::u32::MAX as usize {
70            bail!(
71                "Too many tagged fields to encode ({} fields)",
72                num_tagged_fields
73            );
74        }
75        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
76
77        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
78        Ok(())
79    }
80    fn compute_size(&self, version: i16) -> Result<usize> {
81        let mut total_size = 0;
82        if version >= 1 {
83            total_size += types::CompactArray(types::Int8).compute_size(&self.resource_types)?;
84        } else {
85            if !self.resource_types.is_empty() {
86                bail!("A field is set that is not available on the selected protocol version");
87            }
88        }
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        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
97
98        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
99        Ok(total_size)
100    }
101}
102
103#[cfg(feature = "broker")]
104impl Decodable for ListConfigResourcesRequest {
105    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
106        if version < 0 || version > 1 {
107            bail!("specified version not supported by this message type");
108        }
109        let resource_types = if version >= 1 {
110            types::CompactArray(types::Int8).decode(buf)?
111        } else {
112            Default::default()
113        };
114        let mut unknown_tagged_fields = BTreeMap::new();
115        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
116        for _ in 0..num_tagged_fields {
117            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
118            let size: u32 = types::UnsignedVarInt.decode(buf)?;
119            let unknown_value = buf.try_get_bytes(size as usize)?;
120            unknown_tagged_fields.insert(tag as i32, unknown_value);
121        }
122        Ok(Self {
123            resource_types,
124            unknown_tagged_fields,
125        })
126    }
127}
128
129impl Default for ListConfigResourcesRequest {
130    fn default() -> Self {
131        Self {
132            resource_types: Default::default(),
133            unknown_tagged_fields: BTreeMap::new(),
134        }
135    }
136}
137
138impl Message for ListConfigResourcesRequest {
139    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
140    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
141}
142
143impl HeaderVersion for ListConfigResourcesRequest {
144    fn header_version(version: i16) -> i16 {
145        2
146    }
147}