kafka_protocol/messages/
alter_user_scram_credentials_response.rs1#![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#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct AlterUserScramCredentialsResponse {
24 pub throttle_time_ms: i32,
28
29 pub results: Vec<AlterUserScramCredentialsResult>,
33
34 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl AlterUserScramCredentialsResponse {
39 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
45 self.throttle_time_ms = value;
46 self
47 }
48 pub fn with_results(mut self, value: Vec<AlterUserScramCredentialsResult>) -> Self {
54 self.results = value;
55 self
56 }
57 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
59 self.unknown_tagged_fields = value;
60 self
61 }
62 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 if version != 0 {
73 bail!("specified version not supported by this message type");
74 }
75 types::Int32.encode(buf, &self.throttle_time_ms)?;
76 types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
77 let num_tagged_fields = self.unknown_tagged_fields.len();
78 if num_tagged_fields > std::u32::MAX as usize {
79 bail!(
80 "Too many tagged fields to encode ({} fields)",
81 num_tagged_fields
82 );
83 }
84 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
85
86 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
87 Ok(())
88 }
89 fn compute_size(&self, version: i16) -> Result<usize> {
90 let mut total_size = 0;
91 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
92 total_size += types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
93 let num_tagged_fields = self.unknown_tagged_fields.len();
94 if num_tagged_fields > std::u32::MAX as usize {
95 bail!(
96 "Too many tagged fields to encode ({} fields)",
97 num_tagged_fields
98 );
99 }
100 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
101
102 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
103 Ok(total_size)
104 }
105}
106
107#[cfg(feature = "client")]
108impl Decodable for AlterUserScramCredentialsResponse {
109 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
110 if version != 0 {
111 bail!("specified version not supported by this message type");
112 }
113 let throttle_time_ms = types::Int32.decode(buf)?;
114 let results = types::CompactArray(types::Struct { version }).decode(buf)?;
115 let mut unknown_tagged_fields = BTreeMap::new();
116 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
117 for _ in 0..num_tagged_fields {
118 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
119 let size: u32 = types::UnsignedVarInt.decode(buf)?;
120 let unknown_value = buf.try_get_bytes(size as usize)?;
121 unknown_tagged_fields.insert(tag as i32, unknown_value);
122 }
123 Ok(Self {
124 throttle_time_ms,
125 results,
126 unknown_tagged_fields,
127 })
128 }
129}
130
131impl Default for AlterUserScramCredentialsResponse {
132 fn default() -> Self {
133 Self {
134 throttle_time_ms: 0,
135 results: Default::default(),
136 unknown_tagged_fields: BTreeMap::new(),
137 }
138 }
139}
140
141impl Message for AlterUserScramCredentialsResponse {
142 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
143 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
144}
145
146#[non_exhaustive]
148#[derive(Debug, Clone, PartialEq)]
149pub struct AlterUserScramCredentialsResult {
150 pub user: StrBytes,
154
155 pub error_code: i16,
159
160 pub error_message: Option<StrBytes>,
164
165 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
167}
168
169impl AlterUserScramCredentialsResult {
170 pub fn with_user(mut self, value: StrBytes) -> Self {
176 self.user = value;
177 self
178 }
179 pub fn with_error_code(mut self, value: i16) -> Self {
185 self.error_code = value;
186 self
187 }
188 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
194 self.error_message = value;
195 self
196 }
197 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
199 self.unknown_tagged_fields = value;
200 self
201 }
202 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
204 self.unknown_tagged_fields.insert(key, value);
205 self
206 }
207}
208
209#[cfg(feature = "broker")]
210impl Encodable for AlterUserScramCredentialsResult {
211 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
212 if version != 0 {
213 bail!("specified version not supported by this message type");
214 }
215 types::CompactString.encode(buf, &self.user)?;
216 types::Int16.encode(buf, &self.error_code)?;
217 types::CompactString.encode(buf, &self.error_message)?;
218 let num_tagged_fields = self.unknown_tagged_fields.len();
219 if num_tagged_fields > std::u32::MAX as usize {
220 bail!(
221 "Too many tagged fields to encode ({} fields)",
222 num_tagged_fields
223 );
224 }
225 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
226
227 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
228 Ok(())
229 }
230 fn compute_size(&self, version: i16) -> Result<usize> {
231 let mut total_size = 0;
232 total_size += types::CompactString.compute_size(&self.user)?;
233 total_size += types::Int16.compute_size(&self.error_code)?;
234 total_size += types::CompactString.compute_size(&self.error_message)?;
235 let num_tagged_fields = self.unknown_tagged_fields.len();
236 if num_tagged_fields > std::u32::MAX as usize {
237 bail!(
238 "Too many tagged fields to encode ({} fields)",
239 num_tagged_fields
240 );
241 }
242 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
243
244 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
245 Ok(total_size)
246 }
247}
248
249#[cfg(feature = "client")]
250impl Decodable for AlterUserScramCredentialsResult {
251 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
252 if version != 0 {
253 bail!("specified version not supported by this message type");
254 }
255 let user = types::CompactString.decode(buf)?;
256 let error_code = types::Int16.decode(buf)?;
257 let error_message = types::CompactString.decode(buf)?;
258 let mut unknown_tagged_fields = BTreeMap::new();
259 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
260 for _ in 0..num_tagged_fields {
261 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
262 let size: u32 = types::UnsignedVarInt.decode(buf)?;
263 let unknown_value = buf.try_get_bytes(size as usize)?;
264 unknown_tagged_fields.insert(tag as i32, unknown_value);
265 }
266 Ok(Self {
267 user,
268 error_code,
269 error_message,
270 unknown_tagged_fields,
271 })
272 }
273}
274
275impl Default for AlterUserScramCredentialsResult {
276 fn default() -> Self {
277 Self {
278 user: Default::default(),
279 error_code: 0,
280 error_message: Some(Default::default()),
281 unknown_tagged_fields: BTreeMap::new(),
282 }
283 }
284}
285
286impl Message for AlterUserScramCredentialsResult {
287 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
288 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
289}
290
291impl HeaderVersion for AlterUserScramCredentialsResponse {
292 fn header_version(version: i16) -> i16 {
293 1
294 }
295}