1#![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 CredentialInfo {
24 pub mechanism: i8,
28
29 pub iterations: i32,
33
34 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl CredentialInfo {
39 pub fn with_mechanism(mut self, value: i8) -> Self {
45 self.mechanism = value;
46 self
47 }
48 pub fn with_iterations(mut self, value: i32) -> Self {
54 self.iterations = 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 CredentialInfo {
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::Int8.encode(buf, &self.mechanism)?;
76 types::Int32.encode(buf, &self.iterations)?;
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::Int8.compute_size(&self.mechanism)?;
92 total_size += types::Int32.compute_size(&self.iterations)?;
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 CredentialInfo {
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 mechanism = types::Int8.decode(buf)?;
114 let iterations = types::Int32.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 mechanism,
125 iterations,
126 unknown_tagged_fields,
127 })
128 }
129}
130
131impl Default for CredentialInfo {
132 fn default() -> Self {
133 Self {
134 mechanism: 0,
135 iterations: 0,
136 unknown_tagged_fields: BTreeMap::new(),
137 }
138 }
139}
140
141impl Message for CredentialInfo {
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 DescribeUserScramCredentialsResponse {
150 pub throttle_time_ms: i32,
154
155 pub error_code: i16,
159
160 pub error_message: Option<StrBytes>,
164
165 pub results: Vec<DescribeUserScramCredentialsResult>,
169
170 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
172}
173
174impl DescribeUserScramCredentialsResponse {
175 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
181 self.throttle_time_ms = value;
182 self
183 }
184 pub fn with_error_code(mut self, value: i16) -> Self {
190 self.error_code = value;
191 self
192 }
193 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
199 self.error_message = value;
200 self
201 }
202 pub fn with_results(mut self, value: Vec<DescribeUserScramCredentialsResult>) -> Self {
208 self.results = value;
209 self
210 }
211 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
213 self.unknown_tagged_fields = value;
214 self
215 }
216 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
218 self.unknown_tagged_fields.insert(key, value);
219 self
220 }
221}
222
223#[cfg(feature = "broker")]
224impl Encodable for DescribeUserScramCredentialsResponse {
225 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
226 if version != 0 {
227 bail!("specified version not supported by this message type");
228 }
229 types::Int32.encode(buf, &self.throttle_time_ms)?;
230 types::Int16.encode(buf, &self.error_code)?;
231 types::CompactString.encode(buf, &self.error_message)?;
232 types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
233 let num_tagged_fields = self.unknown_tagged_fields.len();
234 if num_tagged_fields > std::u32::MAX as usize {
235 bail!(
236 "Too many tagged fields to encode ({} fields)",
237 num_tagged_fields
238 );
239 }
240 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
241
242 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
243 Ok(())
244 }
245 fn compute_size(&self, version: i16) -> Result<usize> {
246 let mut total_size = 0;
247 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
248 total_size += types::Int16.compute_size(&self.error_code)?;
249 total_size += types::CompactString.compute_size(&self.error_message)?;
250 total_size += types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
251 let num_tagged_fields = self.unknown_tagged_fields.len();
252 if num_tagged_fields > std::u32::MAX as usize {
253 bail!(
254 "Too many tagged fields to encode ({} fields)",
255 num_tagged_fields
256 );
257 }
258 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
259
260 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
261 Ok(total_size)
262 }
263}
264
265#[cfg(feature = "client")]
266impl Decodable for DescribeUserScramCredentialsResponse {
267 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
268 if version != 0 {
269 bail!("specified version not supported by this message type");
270 }
271 let throttle_time_ms = types::Int32.decode(buf)?;
272 let error_code = types::Int16.decode(buf)?;
273 let error_message = types::CompactString.decode(buf)?;
274 let results = types::CompactArray(types::Struct { version }).decode(buf)?;
275 let mut unknown_tagged_fields = BTreeMap::new();
276 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
277 for _ in 0..num_tagged_fields {
278 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
279 let size: u32 = types::UnsignedVarInt.decode(buf)?;
280 let unknown_value = buf.try_get_bytes(size as usize)?;
281 unknown_tagged_fields.insert(tag as i32, unknown_value);
282 }
283 Ok(Self {
284 throttle_time_ms,
285 error_code,
286 error_message,
287 results,
288 unknown_tagged_fields,
289 })
290 }
291}
292
293impl Default for DescribeUserScramCredentialsResponse {
294 fn default() -> Self {
295 Self {
296 throttle_time_ms: 0,
297 error_code: 0,
298 error_message: Some(Default::default()),
299 results: Default::default(),
300 unknown_tagged_fields: BTreeMap::new(),
301 }
302 }
303}
304
305impl Message for DescribeUserScramCredentialsResponse {
306 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
307 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
308}
309
310#[non_exhaustive]
312#[derive(Debug, Clone, PartialEq)]
313pub struct DescribeUserScramCredentialsResult {
314 pub user: StrBytes,
318
319 pub error_code: i16,
323
324 pub error_message: Option<StrBytes>,
328
329 pub credential_infos: Vec<CredentialInfo>,
333
334 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
336}
337
338impl DescribeUserScramCredentialsResult {
339 pub fn with_user(mut self, value: StrBytes) -> Self {
345 self.user = value;
346 self
347 }
348 pub fn with_error_code(mut self, value: i16) -> Self {
354 self.error_code = value;
355 self
356 }
357 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
363 self.error_message = value;
364 self
365 }
366 pub fn with_credential_infos(mut self, value: Vec<CredentialInfo>) -> Self {
372 self.credential_infos = value;
373 self
374 }
375 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
377 self.unknown_tagged_fields = value;
378 self
379 }
380 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
382 self.unknown_tagged_fields.insert(key, value);
383 self
384 }
385}
386
387#[cfg(feature = "broker")]
388impl Encodable for DescribeUserScramCredentialsResult {
389 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
390 if version != 0 {
391 bail!("specified version not supported by this message type");
392 }
393 types::CompactString.encode(buf, &self.user)?;
394 types::Int16.encode(buf, &self.error_code)?;
395 types::CompactString.encode(buf, &self.error_message)?;
396 types::CompactArray(types::Struct { version }).encode(buf, &self.credential_infos)?;
397 let num_tagged_fields = self.unknown_tagged_fields.len();
398 if num_tagged_fields > std::u32::MAX as usize {
399 bail!(
400 "Too many tagged fields to encode ({} fields)",
401 num_tagged_fields
402 );
403 }
404 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
405
406 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
407 Ok(())
408 }
409 fn compute_size(&self, version: i16) -> Result<usize> {
410 let mut total_size = 0;
411 total_size += types::CompactString.compute_size(&self.user)?;
412 total_size += types::Int16.compute_size(&self.error_code)?;
413 total_size += types::CompactString.compute_size(&self.error_message)?;
414 total_size +=
415 types::CompactArray(types::Struct { version }).compute_size(&self.credential_infos)?;
416 let num_tagged_fields = self.unknown_tagged_fields.len();
417 if num_tagged_fields > std::u32::MAX as usize {
418 bail!(
419 "Too many tagged fields to encode ({} fields)",
420 num_tagged_fields
421 );
422 }
423 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
424
425 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
426 Ok(total_size)
427 }
428}
429
430#[cfg(feature = "client")]
431impl Decodable for DescribeUserScramCredentialsResult {
432 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
433 if version != 0 {
434 bail!("specified version not supported by this message type");
435 }
436 let user = types::CompactString.decode(buf)?;
437 let error_code = types::Int16.decode(buf)?;
438 let error_message = types::CompactString.decode(buf)?;
439 let credential_infos = types::CompactArray(types::Struct { version }).decode(buf)?;
440 let mut unknown_tagged_fields = BTreeMap::new();
441 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
442 for _ in 0..num_tagged_fields {
443 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
444 let size: u32 = types::UnsignedVarInt.decode(buf)?;
445 let unknown_value = buf.try_get_bytes(size as usize)?;
446 unknown_tagged_fields.insert(tag as i32, unknown_value);
447 }
448 Ok(Self {
449 user,
450 error_code,
451 error_message,
452 credential_infos,
453 unknown_tagged_fields,
454 })
455 }
456}
457
458impl Default for DescribeUserScramCredentialsResult {
459 fn default() -> Self {
460 Self {
461 user: Default::default(),
462 error_code: 0,
463 error_message: Some(Default::default()),
464 credential_infos: Default::default(),
465 unknown_tagged_fields: BTreeMap::new(),
466 }
467 }
468}
469
470impl Message for DescribeUserScramCredentialsResult {
471 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
472 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
473}
474
475impl HeaderVersion for DescribeUserScramCredentialsResponse {
476 fn header_version(version: i16) -> i16 {
477 1
478 }
479}