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-2
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct UpdatableFeatureResult {
24    /// The name of the finalized feature.
25    ///
26    /// Supported API versions: 0-2
27    pub feature: StrBytes,
28
29    /// The feature update error code or `0` if the feature update succeeded.
30    ///
31    /// Supported API versions: 0-2
32    pub error_code: i16,
33
34    /// The feature update error, or `null` if the feature update succeeded.
35    ///
36    /// Supported API versions: 0-2
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-2
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-2
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-2
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        if version < 0 || version > 2 {
87            bail!("specified version not supported by this message type");
88        }
89        types::CompactString.encode(buf, &self.feature)?;
90        types::Int16.encode(buf, &self.error_code)?;
91        types::CompactString.encode(buf, &self.error_message)?;
92        let num_tagged_fields = self.unknown_tagged_fields.len();
93        if num_tagged_fields > std::u32::MAX as usize {
94            bail!(
95                "Too many tagged fields to encode ({} fields)",
96                num_tagged_fields
97            );
98        }
99        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
100
101        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
102        Ok(())
103    }
104    fn compute_size(&self, version: i16) -> Result<usize> {
105        let mut total_size = 0;
106        total_size += types::CompactString.compute_size(&self.feature)?;
107        total_size += types::Int16.compute_size(&self.error_code)?;
108        total_size += types::CompactString.compute_size(&self.error_message)?;
109        let num_tagged_fields = self.unknown_tagged_fields.len();
110        if num_tagged_fields > std::u32::MAX as usize {
111            bail!(
112                "Too many tagged fields to encode ({} fields)",
113                num_tagged_fields
114            );
115        }
116        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
117
118        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
119        Ok(total_size)
120    }
121}
122
123#[cfg(feature = "client")]
124impl Decodable for UpdatableFeatureResult {
125    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
126        if version < 0 || version > 2 {
127            bail!("specified version not supported by this message type");
128        }
129        let feature = types::CompactString.decode(buf)?;
130        let error_code = types::Int16.decode(buf)?;
131        let error_message = types::CompactString.decode(buf)?;
132        let mut unknown_tagged_fields = BTreeMap::new();
133        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
134        for _ in 0..num_tagged_fields {
135            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
136            let size: u32 = types::UnsignedVarInt.decode(buf)?;
137            let unknown_value = buf.try_get_bytes(size as usize)?;
138            unknown_tagged_fields.insert(tag as i32, unknown_value);
139        }
140        Ok(Self {
141            feature,
142            error_code,
143            error_message,
144            unknown_tagged_fields,
145        })
146    }
147}
148
149impl Default for UpdatableFeatureResult {
150    fn default() -> Self {
151        Self {
152            feature: Default::default(),
153            error_code: 0,
154            error_message: Some(Default::default()),
155            unknown_tagged_fields: BTreeMap::new(),
156        }
157    }
158}
159
160impl Message for UpdatableFeatureResult {
161    const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
162    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
163}
164
165/// Valid versions: 0-2
166#[non_exhaustive]
167#[derive(Debug, Clone, PartialEq)]
168pub struct UpdateFeaturesResponse {
169    /// 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.
170    ///
171    /// Supported API versions: 0-2
172    pub throttle_time_ms: i32,
173
174    /// The top-level error code, or `0` if there was no top-level error.
175    ///
176    /// Supported API versions: 0-2
177    pub error_code: i16,
178
179    /// The top-level error message, or `null` if there was no top-level error.
180    ///
181    /// Supported API versions: 0-2
182    pub error_message: Option<StrBytes>,
183
184    /// Results for each feature update.
185    ///
186    /// Supported API versions: 0-1
187    pub results: Vec<UpdatableFeatureResult>,
188
189    /// Other tagged fields
190    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
191}
192
193impl UpdateFeaturesResponse {
194    /// Sets `throttle_time_ms` to the passed value.
195    ///
196    /// 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.
197    ///
198    /// Supported API versions: 0-2
199    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
200        self.throttle_time_ms = value;
201        self
202    }
203    /// Sets `error_code` to the passed value.
204    ///
205    /// The top-level error code, or `0` if there was no top-level error.
206    ///
207    /// Supported API versions: 0-2
208    pub fn with_error_code(mut self, value: i16) -> Self {
209        self.error_code = value;
210        self
211    }
212    /// Sets `error_message` to the passed value.
213    ///
214    /// The top-level error message, or `null` if there was no top-level error.
215    ///
216    /// Supported API versions: 0-2
217    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
218        self.error_message = value;
219        self
220    }
221    /// Sets `results` to the passed value.
222    ///
223    /// Results for each feature update.
224    ///
225    /// Supported API versions: 0-1
226    pub fn with_results(mut self, value: Vec<UpdatableFeatureResult>) -> Self {
227        self.results = value;
228        self
229    }
230    /// Sets unknown_tagged_fields to the passed value.
231    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
232        self.unknown_tagged_fields = value;
233        self
234    }
235    /// Inserts an entry into unknown_tagged_fields.
236    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
237        self.unknown_tagged_fields.insert(key, value);
238        self
239    }
240}
241
242#[cfg(feature = "broker")]
243impl Encodable for UpdateFeaturesResponse {
244    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
245        if version < 0 || version > 2 {
246            bail!("specified version not supported by this message type");
247        }
248        types::Int32.encode(buf, &self.throttle_time_ms)?;
249        types::Int16.encode(buf, &self.error_code)?;
250        types::CompactString.encode(buf, &self.error_message)?;
251        if version <= 1 {
252            types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
253        }
254        let num_tagged_fields = self.unknown_tagged_fields.len();
255        if num_tagged_fields > std::u32::MAX as usize {
256            bail!(
257                "Too many tagged fields to encode ({} fields)",
258                num_tagged_fields
259            );
260        }
261        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
262
263        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
264        Ok(())
265    }
266    fn compute_size(&self, version: i16) -> Result<usize> {
267        let mut total_size = 0;
268        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
269        total_size += types::Int16.compute_size(&self.error_code)?;
270        total_size += types::CompactString.compute_size(&self.error_message)?;
271        if version <= 1 {
272            total_size +=
273                types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
274        }
275        let num_tagged_fields = self.unknown_tagged_fields.len();
276        if num_tagged_fields > std::u32::MAX as usize {
277            bail!(
278                "Too many tagged fields to encode ({} fields)",
279                num_tagged_fields
280            );
281        }
282        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
283
284        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
285        Ok(total_size)
286    }
287}
288
289#[cfg(feature = "client")]
290impl Decodable for UpdateFeaturesResponse {
291    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
292        if version < 0 || version > 2 {
293            bail!("specified version not supported by this message type");
294        }
295        let throttle_time_ms = types::Int32.decode(buf)?;
296        let error_code = types::Int16.decode(buf)?;
297        let error_message = types::CompactString.decode(buf)?;
298        let results = if version <= 1 {
299            types::CompactArray(types::Struct { version }).decode(buf)?
300        } else {
301            Default::default()
302        };
303        let mut unknown_tagged_fields = BTreeMap::new();
304        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
305        for _ in 0..num_tagged_fields {
306            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
307            let size: u32 = types::UnsignedVarInt.decode(buf)?;
308            let unknown_value = buf.try_get_bytes(size as usize)?;
309            unknown_tagged_fields.insert(tag as i32, unknown_value);
310        }
311        Ok(Self {
312            throttle_time_ms,
313            error_code,
314            error_message,
315            results,
316            unknown_tagged_fields,
317        })
318    }
319}
320
321impl Default for UpdateFeaturesResponse {
322    fn default() -> Self {
323        Self {
324            throttle_time_ms: 0,
325            error_code: 0,
326            error_message: Some(Default::default()),
327            results: Default::default(),
328            unknown_tagged_fields: BTreeMap::new(),
329        }
330    }
331}
332
333impl Message for UpdateFeaturesResponse {
334    const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
335    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
336}
337
338impl HeaderVersion for UpdateFeaturesResponse {
339    fn header_version(version: i16) -> i16 {
340        1
341    }
342}