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 AlterUserScramCredentialsRequest {
24 pub deletions: Vec<ScramCredentialDeletion>,
28
29 pub upsertions: Vec<ScramCredentialUpsertion>,
33
34 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl AlterUserScramCredentialsRequest {
39 pub fn with_deletions(mut self, value: Vec<ScramCredentialDeletion>) -> Self {
45 self.deletions = value;
46 self
47 }
48 pub fn with_upsertions(mut self, value: Vec<ScramCredentialUpsertion>) -> Self {
54 self.upsertions = 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 = "client")]
70impl Encodable for AlterUserScramCredentialsRequest {
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::CompactArray(types::Struct { version }).encode(buf, &self.deletions)?;
76 types::CompactArray(types::Struct { version }).encode(buf, &self.upsertions)?;
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 +=
92 types::CompactArray(types::Struct { version }).compute_size(&self.deletions)?;
93 total_size +=
94 types::CompactArray(types::Struct { version }).compute_size(&self.upsertions)?;
95 let num_tagged_fields = self.unknown_tagged_fields.len();
96 if num_tagged_fields > std::u32::MAX as usize {
97 bail!(
98 "Too many tagged fields to encode ({} fields)",
99 num_tagged_fields
100 );
101 }
102 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
103
104 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
105 Ok(total_size)
106 }
107}
108
109#[cfg(feature = "broker")]
110impl Decodable for AlterUserScramCredentialsRequest {
111 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
112 if version != 0 {
113 bail!("specified version not supported by this message type");
114 }
115 let deletions = types::CompactArray(types::Struct { version }).decode(buf)?;
116 let upsertions = types::CompactArray(types::Struct { version }).decode(buf)?;
117 let mut unknown_tagged_fields = BTreeMap::new();
118 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
119 for _ in 0..num_tagged_fields {
120 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
121 let size: u32 = types::UnsignedVarInt.decode(buf)?;
122 let unknown_value = buf.try_get_bytes(size as usize)?;
123 unknown_tagged_fields.insert(tag as i32, unknown_value);
124 }
125 Ok(Self {
126 deletions,
127 upsertions,
128 unknown_tagged_fields,
129 })
130 }
131}
132
133impl Default for AlterUserScramCredentialsRequest {
134 fn default() -> Self {
135 Self {
136 deletions: Default::default(),
137 upsertions: Default::default(),
138 unknown_tagged_fields: BTreeMap::new(),
139 }
140 }
141}
142
143impl Message for AlterUserScramCredentialsRequest {
144 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
145 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
146}
147
148#[non_exhaustive]
150#[derive(Debug, Clone, PartialEq)]
151pub struct ScramCredentialDeletion {
152 pub name: StrBytes,
156
157 pub mechanism: i8,
161
162 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
164}
165
166impl ScramCredentialDeletion {
167 pub fn with_name(mut self, value: StrBytes) -> Self {
173 self.name = value;
174 self
175 }
176 pub fn with_mechanism(mut self, value: i8) -> Self {
182 self.mechanism = value;
183 self
184 }
185 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
187 self.unknown_tagged_fields = value;
188 self
189 }
190 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
192 self.unknown_tagged_fields.insert(key, value);
193 self
194 }
195}
196
197#[cfg(feature = "client")]
198impl Encodable for ScramCredentialDeletion {
199 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
200 if version != 0 {
201 bail!("specified version not supported by this message type");
202 }
203 types::CompactString.encode(buf, &self.name)?;
204 types::Int8.encode(buf, &self.mechanism)?;
205 let num_tagged_fields = self.unknown_tagged_fields.len();
206 if num_tagged_fields > std::u32::MAX as usize {
207 bail!(
208 "Too many tagged fields to encode ({} fields)",
209 num_tagged_fields
210 );
211 }
212 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
213
214 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
215 Ok(())
216 }
217 fn compute_size(&self, version: i16) -> Result<usize> {
218 let mut total_size = 0;
219 total_size += types::CompactString.compute_size(&self.name)?;
220 total_size += types::Int8.compute_size(&self.mechanism)?;
221 let num_tagged_fields = self.unknown_tagged_fields.len();
222 if num_tagged_fields > std::u32::MAX as usize {
223 bail!(
224 "Too many tagged fields to encode ({} fields)",
225 num_tagged_fields
226 );
227 }
228 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
229
230 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
231 Ok(total_size)
232 }
233}
234
235#[cfg(feature = "broker")]
236impl Decodable for ScramCredentialDeletion {
237 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
238 if version != 0 {
239 bail!("specified version not supported by this message type");
240 }
241 let name = types::CompactString.decode(buf)?;
242 let mechanism = types::Int8.decode(buf)?;
243 let mut unknown_tagged_fields = BTreeMap::new();
244 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
245 for _ in 0..num_tagged_fields {
246 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
247 let size: u32 = types::UnsignedVarInt.decode(buf)?;
248 let unknown_value = buf.try_get_bytes(size as usize)?;
249 unknown_tagged_fields.insert(tag as i32, unknown_value);
250 }
251 Ok(Self {
252 name,
253 mechanism,
254 unknown_tagged_fields,
255 })
256 }
257}
258
259impl Default for ScramCredentialDeletion {
260 fn default() -> Self {
261 Self {
262 name: Default::default(),
263 mechanism: 0,
264 unknown_tagged_fields: BTreeMap::new(),
265 }
266 }
267}
268
269impl Message for ScramCredentialDeletion {
270 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
271 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
272}
273
274#[non_exhaustive]
276#[derive(Debug, Clone, PartialEq)]
277pub struct ScramCredentialUpsertion {
278 pub name: StrBytes,
282
283 pub mechanism: i8,
287
288 pub iterations: i32,
292
293 pub salt: Bytes,
297
298 pub salted_password: Bytes,
302
303 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
305}
306
307impl ScramCredentialUpsertion {
308 pub fn with_name(mut self, value: StrBytes) -> Self {
314 self.name = value;
315 self
316 }
317 pub fn with_mechanism(mut self, value: i8) -> Self {
323 self.mechanism = value;
324 self
325 }
326 pub fn with_iterations(mut self, value: i32) -> Self {
332 self.iterations = value;
333 self
334 }
335 pub fn with_salt(mut self, value: Bytes) -> Self {
341 self.salt = value;
342 self
343 }
344 pub fn with_salted_password(mut self, value: Bytes) -> Self {
350 self.salted_password = value;
351 self
352 }
353 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
355 self.unknown_tagged_fields = value;
356 self
357 }
358 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
360 self.unknown_tagged_fields.insert(key, value);
361 self
362 }
363}
364
365#[cfg(feature = "client")]
366impl Encodable for ScramCredentialUpsertion {
367 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
368 if version != 0 {
369 bail!("specified version not supported by this message type");
370 }
371 types::CompactString.encode(buf, &self.name)?;
372 types::Int8.encode(buf, &self.mechanism)?;
373 types::Int32.encode(buf, &self.iterations)?;
374 types::CompactBytes.encode(buf, &self.salt)?;
375 types::CompactBytes.encode(buf, &self.salted_password)?;
376 let num_tagged_fields = self.unknown_tagged_fields.len();
377 if num_tagged_fields > std::u32::MAX as usize {
378 bail!(
379 "Too many tagged fields to encode ({} fields)",
380 num_tagged_fields
381 );
382 }
383 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
384
385 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
386 Ok(())
387 }
388 fn compute_size(&self, version: i16) -> Result<usize> {
389 let mut total_size = 0;
390 total_size += types::CompactString.compute_size(&self.name)?;
391 total_size += types::Int8.compute_size(&self.mechanism)?;
392 total_size += types::Int32.compute_size(&self.iterations)?;
393 total_size += types::CompactBytes.compute_size(&self.salt)?;
394 total_size += types::CompactBytes.compute_size(&self.salted_password)?;
395 let num_tagged_fields = self.unknown_tagged_fields.len();
396 if num_tagged_fields > std::u32::MAX as usize {
397 bail!(
398 "Too many tagged fields to encode ({} fields)",
399 num_tagged_fields
400 );
401 }
402 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
403
404 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
405 Ok(total_size)
406 }
407}
408
409#[cfg(feature = "broker")]
410impl Decodable for ScramCredentialUpsertion {
411 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
412 if version != 0 {
413 bail!("specified version not supported by this message type");
414 }
415 let name = types::CompactString.decode(buf)?;
416 let mechanism = types::Int8.decode(buf)?;
417 let iterations = types::Int32.decode(buf)?;
418 let salt = types::CompactBytes.decode(buf)?;
419 let salted_password = types::CompactBytes.decode(buf)?;
420 let mut unknown_tagged_fields = BTreeMap::new();
421 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
422 for _ in 0..num_tagged_fields {
423 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
424 let size: u32 = types::UnsignedVarInt.decode(buf)?;
425 let unknown_value = buf.try_get_bytes(size as usize)?;
426 unknown_tagged_fields.insert(tag as i32, unknown_value);
427 }
428 Ok(Self {
429 name,
430 mechanism,
431 iterations,
432 salt,
433 salted_password,
434 unknown_tagged_fields,
435 })
436 }
437}
438
439impl Default for ScramCredentialUpsertion {
440 fn default() -> Self {
441 Self {
442 name: Default::default(),
443 mechanism: 0,
444 iterations: 0,
445 salt: Default::default(),
446 salted_password: Default::default(),
447 unknown_tagged_fields: BTreeMap::new(),
448 }
449 }
450}
451
452impl Message for ScramCredentialUpsertion {
453 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
454 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
455}
456
457impl HeaderVersion for AlterUserScramCredentialsRequest {
458 fn header_version(version: i16) -> i16 {
459 2
460 }
461}