kafka_protocol/messages/
alter_user_scram_credentials_response.rs

1//! AlterUserScramCredentialsResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/AlterUserScramCredentialsResponse.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
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct AlterUserScramCredentialsResponse {
24    /// 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.
25    ///
26    /// Supported API versions: 0
27    pub throttle_time_ms: i32,
28
29    /// The results for deletions and alterations, one per affected user.
30    ///
31    /// Supported API versions: 0
32    pub results: Vec<AlterUserScramCredentialsResult>,
33
34    /// Other tagged fields
35    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl AlterUserScramCredentialsResponse {
39    /// Sets `throttle_time_ms` to the passed value.
40    ///
41    /// 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.
42    ///
43    /// Supported API versions: 0
44    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
45        self.throttle_time_ms = value;
46        self
47    }
48    /// Sets `results` to the passed value.
49    ///
50    /// The results for deletions and alterations, one per affected user.
51    ///
52    /// Supported API versions: 0
53    pub fn with_results(mut self, value: Vec<AlterUserScramCredentialsResult>) -> Self {
54        self.results = value;
55        self
56    }
57    /// Sets unknown_tagged_fields to the passed value.
58    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
59        self.unknown_tagged_fields = value;
60        self
61    }
62    /// Inserts an entry into unknown_tagged_fields.
63    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
64        self.unknown_tagged_fields.insert(key, value);
65        self
66    }
67}
68
69#[cfg(feature = "broker")]
70impl Encodable for AlterUserScramCredentialsResponse {
71    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
72        types::Int32.encode(buf, &self.throttle_time_ms)?;
73        types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
74        let num_tagged_fields = self.unknown_tagged_fields.len();
75        if num_tagged_fields > std::u32::MAX as usize {
76            bail!(
77                "Too many tagged fields to encode ({} fields)",
78                num_tagged_fields
79            );
80        }
81        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
82
83        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
84        Ok(())
85    }
86    fn compute_size(&self, version: i16) -> Result<usize> {
87        let mut total_size = 0;
88        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
89        total_size += types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
90        let num_tagged_fields = self.unknown_tagged_fields.len();
91        if num_tagged_fields > std::u32::MAX as usize {
92            bail!(
93                "Too many tagged fields to encode ({} fields)",
94                num_tagged_fields
95            );
96        }
97        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
98
99        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
100        Ok(total_size)
101    }
102}
103
104#[cfg(feature = "client")]
105impl Decodable for AlterUserScramCredentialsResponse {
106    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
107        let throttle_time_ms = types::Int32.decode(buf)?;
108        let results = types::CompactArray(types::Struct { version }).decode(buf)?;
109        let mut unknown_tagged_fields = BTreeMap::new();
110        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
111        for _ in 0..num_tagged_fields {
112            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
113            let size: u32 = types::UnsignedVarInt.decode(buf)?;
114            let unknown_value = buf.try_get_bytes(size as usize)?;
115            unknown_tagged_fields.insert(tag as i32, unknown_value);
116        }
117        Ok(Self {
118            throttle_time_ms,
119            results,
120            unknown_tagged_fields,
121        })
122    }
123}
124
125impl Default for AlterUserScramCredentialsResponse {
126    fn default() -> Self {
127        Self {
128            throttle_time_ms: 0,
129            results: Default::default(),
130            unknown_tagged_fields: BTreeMap::new(),
131        }
132    }
133}
134
135impl Message for AlterUserScramCredentialsResponse {
136    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
137    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
138}
139
140/// Valid versions: 0
141#[non_exhaustive]
142#[derive(Debug, Clone, PartialEq)]
143pub struct AlterUserScramCredentialsResult {
144    /// The user name.
145    ///
146    /// Supported API versions: 0
147    pub user: StrBytes,
148
149    /// The error code.
150    ///
151    /// Supported API versions: 0
152    pub error_code: i16,
153
154    /// The error message, if any.
155    ///
156    /// Supported API versions: 0
157    pub error_message: Option<StrBytes>,
158
159    /// Other tagged fields
160    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
161}
162
163impl AlterUserScramCredentialsResult {
164    /// Sets `user` to the passed value.
165    ///
166    /// The user name.
167    ///
168    /// Supported API versions: 0
169    pub fn with_user(mut self, value: StrBytes) -> Self {
170        self.user = value;
171        self
172    }
173    /// Sets `error_code` to the passed value.
174    ///
175    /// The error code.
176    ///
177    /// Supported API versions: 0
178    pub fn with_error_code(mut self, value: i16) -> Self {
179        self.error_code = value;
180        self
181    }
182    /// Sets `error_message` to the passed value.
183    ///
184    /// The error message, if any.
185    ///
186    /// Supported API versions: 0
187    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
188        self.error_message = value;
189        self
190    }
191    /// Sets unknown_tagged_fields to the passed value.
192    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
193        self.unknown_tagged_fields = value;
194        self
195    }
196    /// Inserts an entry into unknown_tagged_fields.
197    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
198        self.unknown_tagged_fields.insert(key, value);
199        self
200    }
201}
202
203#[cfg(feature = "broker")]
204impl Encodable for AlterUserScramCredentialsResult {
205    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
206        types::CompactString.encode(buf, &self.user)?;
207        types::Int16.encode(buf, &self.error_code)?;
208        types::CompactString.encode(buf, &self.error_message)?;
209        let num_tagged_fields = self.unknown_tagged_fields.len();
210        if num_tagged_fields > std::u32::MAX as usize {
211            bail!(
212                "Too many tagged fields to encode ({} fields)",
213                num_tagged_fields
214            );
215        }
216        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
217
218        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
219        Ok(())
220    }
221    fn compute_size(&self, version: i16) -> Result<usize> {
222        let mut total_size = 0;
223        total_size += types::CompactString.compute_size(&self.user)?;
224        total_size += types::Int16.compute_size(&self.error_code)?;
225        total_size += types::CompactString.compute_size(&self.error_message)?;
226        let num_tagged_fields = self.unknown_tagged_fields.len();
227        if num_tagged_fields > std::u32::MAX as usize {
228            bail!(
229                "Too many tagged fields to encode ({} fields)",
230                num_tagged_fields
231            );
232        }
233        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
234
235        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
236        Ok(total_size)
237    }
238}
239
240#[cfg(feature = "client")]
241impl Decodable for AlterUserScramCredentialsResult {
242    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
243        let user = types::CompactString.decode(buf)?;
244        let error_code = types::Int16.decode(buf)?;
245        let error_message = types::CompactString.decode(buf)?;
246        let mut unknown_tagged_fields = BTreeMap::new();
247        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
248        for _ in 0..num_tagged_fields {
249            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
250            let size: u32 = types::UnsignedVarInt.decode(buf)?;
251            let unknown_value = buf.try_get_bytes(size as usize)?;
252            unknown_tagged_fields.insert(tag as i32, unknown_value);
253        }
254        Ok(Self {
255            user,
256            error_code,
257            error_message,
258            unknown_tagged_fields,
259        })
260    }
261}
262
263impl Default for AlterUserScramCredentialsResult {
264    fn default() -> Self {
265        Self {
266            user: Default::default(),
267            error_code: 0,
268            error_message: Some(Default::default()),
269            unknown_tagged_fields: BTreeMap::new(),
270        }
271    }
272}
273
274impl Message for AlterUserScramCredentialsResult {
275    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
276    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
277}
278
279impl HeaderVersion for AlterUserScramCredentialsResponse {
280    fn header_version(version: i16) -> i16 {
281        1
282    }
283}