kafka_protocol/messages/
update_features_response.rs

1//! UpdateFeaturesResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/UpdateFeaturesResponse.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 UpdatableFeatureResult {
24    /// The name of the finalized feature.
25    ///
26    /// Supported API versions: 0-1
27    pub feature: StrBytes,
28
29    /// The feature update error code or `0` if the feature update succeeded.
30    ///
31    /// Supported API versions: 0-1
32    pub error_code: i16,
33
34    /// The feature update error, or `null` if the feature update succeeded.
35    ///
36    /// Supported API versions: 0-1
37    pub error_message: Option<StrBytes>,
38
39    /// Other tagged fields
40    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl UpdatableFeatureResult {
44    /// Sets `feature` to the passed value.
45    ///
46    /// The name of the finalized feature.
47    ///
48    /// Supported API versions: 0-1
49    pub fn with_feature(mut self, value: StrBytes) -> Self {
50        self.feature = value;
51        self
52    }
53    /// Sets `error_code` to the passed value.
54    ///
55    /// The feature update error code or `0` if the feature update succeeded.
56    ///
57    /// Supported API versions: 0-1
58    pub fn with_error_code(mut self, value: i16) -> Self {
59        self.error_code = value;
60        self
61    }
62    /// Sets `error_message` to the passed value.
63    ///
64    /// The feature update error, or `null` if the feature update succeeded.
65    ///
66    /// Supported API versions: 0-1
67    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
68        self.error_message = 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 = "broker")]
84impl Encodable for UpdatableFeatureResult {
85    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86        types::CompactString.encode(buf, &self.feature)?;
87        types::Int16.encode(buf, &self.error_code)?;
88        types::CompactString.encode(buf, &self.error_message)?;
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        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
97
98        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
99        Ok(())
100    }
101    fn compute_size(&self, version: i16) -> Result<usize> {
102        let mut total_size = 0;
103        total_size += types::CompactString.compute_size(&self.feature)?;
104        total_size += types::Int16.compute_size(&self.error_code)?;
105        total_size += types::CompactString.compute_size(&self.error_message)?;
106        let num_tagged_fields = self.unknown_tagged_fields.len();
107        if num_tagged_fields > std::u32::MAX as usize {
108            bail!(
109                "Too many tagged fields to encode ({} fields)",
110                num_tagged_fields
111            );
112        }
113        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
114
115        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
116        Ok(total_size)
117    }
118}
119
120#[cfg(feature = "client")]
121impl Decodable for UpdatableFeatureResult {
122    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
123        let feature = types::CompactString.decode(buf)?;
124        let error_code = types::Int16.decode(buf)?;
125        let error_message = types::CompactString.decode(buf)?;
126        let mut unknown_tagged_fields = BTreeMap::new();
127        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
128        for _ in 0..num_tagged_fields {
129            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
130            let size: u32 = types::UnsignedVarInt.decode(buf)?;
131            let unknown_value = buf.try_get_bytes(size as usize)?;
132            unknown_tagged_fields.insert(tag as i32, unknown_value);
133        }
134        Ok(Self {
135            feature,
136            error_code,
137            error_message,
138            unknown_tagged_fields,
139        })
140    }
141}
142
143impl Default for UpdatableFeatureResult {
144    fn default() -> Self {
145        Self {
146            feature: Default::default(),
147            error_code: 0,
148            error_message: Some(Default::default()),
149            unknown_tagged_fields: BTreeMap::new(),
150        }
151    }
152}
153
154impl Message for UpdatableFeatureResult {
155    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
156    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
157}
158
159/// Valid versions: 0-1
160#[non_exhaustive]
161#[derive(Debug, Clone, PartialEq)]
162pub struct UpdateFeaturesResponse {
163    /// 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.
164    ///
165    /// Supported API versions: 0-1
166    pub throttle_time_ms: i32,
167
168    /// The top-level error code, or `0` if there was no top-level error.
169    ///
170    /// Supported API versions: 0-1
171    pub error_code: i16,
172
173    /// The top-level error message, or `null` if there was no top-level error.
174    ///
175    /// Supported API versions: 0-1
176    pub error_message: Option<StrBytes>,
177
178    /// Results for each feature update.
179    ///
180    /// Supported API versions: 0-1
181    pub results: Vec<UpdatableFeatureResult>,
182
183    /// Other tagged fields
184    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
185}
186
187impl UpdateFeaturesResponse {
188    /// Sets `throttle_time_ms` to the passed value.
189    ///
190    /// 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.
191    ///
192    /// Supported API versions: 0-1
193    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
194        self.throttle_time_ms = value;
195        self
196    }
197    /// Sets `error_code` to the passed value.
198    ///
199    /// The top-level error code, or `0` if there was no top-level error.
200    ///
201    /// Supported API versions: 0-1
202    pub fn with_error_code(mut self, value: i16) -> Self {
203        self.error_code = value;
204        self
205    }
206    /// Sets `error_message` to the passed value.
207    ///
208    /// The top-level error message, or `null` if there was no top-level error.
209    ///
210    /// Supported API versions: 0-1
211    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
212        self.error_message = value;
213        self
214    }
215    /// Sets `results` to the passed value.
216    ///
217    /// Results for each feature update.
218    ///
219    /// Supported API versions: 0-1
220    pub fn with_results(mut self, value: Vec<UpdatableFeatureResult>) -> Self {
221        self.results = value;
222        self
223    }
224    /// Sets unknown_tagged_fields to the passed value.
225    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
226        self.unknown_tagged_fields = value;
227        self
228    }
229    /// Inserts an entry into unknown_tagged_fields.
230    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
231        self.unknown_tagged_fields.insert(key, value);
232        self
233    }
234}
235
236#[cfg(feature = "broker")]
237impl Encodable for UpdateFeaturesResponse {
238    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
239        types::Int32.encode(buf, &self.throttle_time_ms)?;
240        types::Int16.encode(buf, &self.error_code)?;
241        types::CompactString.encode(buf, &self.error_message)?;
242        types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
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        Ok(())
254    }
255    fn compute_size(&self, version: i16) -> Result<usize> {
256        let mut total_size = 0;
257        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
258        total_size += types::Int16.compute_size(&self.error_code)?;
259        total_size += types::CompactString.compute_size(&self.error_message)?;
260        total_size += types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
261        let num_tagged_fields = self.unknown_tagged_fields.len();
262        if num_tagged_fields > std::u32::MAX as usize {
263            bail!(
264                "Too many tagged fields to encode ({} fields)",
265                num_tagged_fields
266            );
267        }
268        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
269
270        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
271        Ok(total_size)
272    }
273}
274
275#[cfg(feature = "client")]
276impl Decodable for UpdateFeaturesResponse {
277    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
278        let throttle_time_ms = types::Int32.decode(buf)?;
279        let error_code = types::Int16.decode(buf)?;
280        let error_message = types::CompactString.decode(buf)?;
281        let results = types::CompactArray(types::Struct { version }).decode(buf)?;
282        let mut unknown_tagged_fields = BTreeMap::new();
283        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
284        for _ in 0..num_tagged_fields {
285            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
286            let size: u32 = types::UnsignedVarInt.decode(buf)?;
287            let unknown_value = buf.try_get_bytes(size as usize)?;
288            unknown_tagged_fields.insert(tag as i32, unknown_value);
289        }
290        Ok(Self {
291            throttle_time_ms,
292            error_code,
293            error_message,
294            results,
295            unknown_tagged_fields,
296        })
297    }
298}
299
300impl Default for UpdateFeaturesResponse {
301    fn default() -> Self {
302        Self {
303            throttle_time_ms: 0,
304            error_code: 0,
305            error_message: Some(Default::default()),
306            results: Default::default(),
307            unknown_tagged_fields: BTreeMap::new(),
308        }
309    }
310}
311
312impl Message for UpdateFeaturesResponse {
313    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
314    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
315}
316
317impl HeaderVersion for UpdateFeaturesResponse {
318    fn header_version(version: i16) -> i16 {
319        1
320    }
321}