krabka_protocol/opt/rustwide/workdir/generated/
AlterUserScramCredentialsRequest.borrowed.rs1use bytes::{BufMut, Bytes};
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 primitives::{
7 fixed::{get_i8, get_i32, put_i8, put_i32},
8 string_bytes::{
9 compact_string_len, put_bytes, put_compact_bytes, put_compact_string, put_string,
10 string_len,
11 },
12 string_bytes_borrowed::{
13 get_bytes_borrowed, get_compact_bytes_borrowed, get_compact_string_borrowed,
14 get_string_borrowed,
15 },
16 },
17 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 51;
20pub const MIN_VERSION: i16 = 0;
21pub const MAX_VERSION: i16 = 0;
22pub const LATEST_STABLE_VERSION: i16 = 0;
23pub const FLEXIBLE_MIN: i16 = 0;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27 version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq, Default)]
30pub struct AlterUserScramCredentialsRequest<'a> {
31 pub deletions: Vec<ScramCredentialDeletion<'a>>,
32 pub upsertions: Vec<ScramCredentialUpsertion<'a>>,
33 pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl AlterUserScramCredentialsRequest<'_> {
36 #[must_use]
40 pub fn to_owned(
41 &self,
42 ) -> crate::owned::alter_user_scram_credentials_request::AlterUserScramCredentialsRequest {
43 crate::owned::alter_user_scram_credentials_request::AlterUserScramCredentialsRequest {
44 deletions: (self.deletions)
45 .iter()
46 .map(ScramCredentialDeletion::to_owned)
47 .collect(),
48 upsertions: (self.upsertions)
49 .iter()
50 .map(ScramCredentialUpsertion::to_owned)
51 .collect(),
52 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
53 }
54 }
55}
56impl Encode for AlterUserScramCredentialsRequest<'_> {
57 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
58 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
59 return Err(ProtocolError::UnsupportedVersion {
60 api_key: API_KEY,
61 version,
62 });
63 }
64 let flex = is_flexible(version);
65 if version >= 0 {
66 {
67 crate::primitives::array::put_array_len(buf, (self.deletions).len(), flex);
68 for it in &self.deletions {
69 it.encode(buf, version)?;
70 }
71 };
72 }
73 if version >= 0 {
74 {
75 crate::primitives::array::put_array_len(buf, (self.upsertions).len(), flex);
76 for it in &self.upsertions {
77 it.encode(buf, version)?;
78 }
79 };
80 }
81 if flex {
82 let tagged = WriteTaggedFields::new();
83 tagged.write(buf, &self.unknown_tagged_fields);
84 }
85 Ok(())
86 }
87 fn encoded_len(&self, version: i16) -> usize {
88 let flex = is_flexible(version);
89 let mut n: usize = 0;
90 if version >= 0 {
91 n += {
92 let prefix =
93 crate::primitives::array::array_len_prefix_len((self.deletions).len(), flex);
94 let body: usize = (self.deletions)
95 .iter()
96 .map(|it| it.encoded_len(version))
97 .sum();
98 prefix + body
99 };
100 }
101 if version >= 0 {
102 n += {
103 let prefix =
104 crate::primitives::array::array_len_prefix_len((self.upsertions).len(), flex);
105 let body: usize = (self.upsertions)
106 .iter()
107 .map(|it| it.encoded_len(version))
108 .sum();
109 prefix + body
110 };
111 }
112 if flex {
113 let known_pairs: Vec<(u32, usize)> = Vec::new();
114 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
115 }
116 n
117 }
118}
119impl<'de> DecodeBorrow<'de> for AlterUserScramCredentialsRequest<'de> {
120 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
121 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
122 return Err(ProtocolError::UnsupportedVersion {
123 api_key: API_KEY,
124 version,
125 });
126 }
127 let flex = is_flexible(version);
128 let mut out = Self::default();
129 if version >= 0 {
130 out.deletions = {
131 let n = crate::primitives::array::get_array_len(buf, flex)?;
132 let mut v = Vec::with_capacity(n);
133 for _ in 0..n {
134 v.push(ScramCredentialDeletion::decode_borrow(buf, version)?);
135 }
136 v
137 };
138 }
139 if version >= 0 {
140 out.upsertions = {
141 let n = crate::primitives::array::get_array_len(buf, flex)?;
142 let mut v = Vec::with_capacity(n);
143 for _ in 0..n {
144 v.push(ScramCredentialUpsertion::decode_borrow(buf, version)?);
145 }
146 v
147 };
148 }
149 if flex {
150 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
151 }
152 Ok(out)
153 }
154}
155#[cfg(test)]
156impl AlterUserScramCredentialsRequest<'_> {
157 #[must_use]
158 pub fn populated(version: i16) -> Self {
159 let mut m = Self::default();
160 if version >= 0 {
161 m.deletions = vec![ScramCredentialDeletion::populated(version)];
162 }
163 if version >= 0 {
164 m.upsertions = vec![ScramCredentialUpsertion::populated(version)];
165 }
166 m
167 }
168}
169#[derive(Debug, Clone, PartialEq, Eq, Default)]
170pub struct ScramCredentialDeletion<'a> {
171 pub name: &'a str,
172 pub mechanism: i8,
173 pub unknown_tagged_fields: UnknownTaggedFields,
174}
175impl ScramCredentialDeletion<'_> {
176 #[must_use]
180 pub fn to_owned(
181 &self,
182 ) -> crate::owned::alter_user_scram_credentials_request::ScramCredentialDeletion {
183 crate::owned::alter_user_scram_credentials_request::ScramCredentialDeletion {
184 name: (self.name).to_string(),
185 mechanism: (self.mechanism),
186 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
187 }
188 }
189}
190impl Encode for ScramCredentialDeletion<'_> {
191 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
192 let flex = version >= 0;
193 if version >= 0 {
194 if flex {
195 let () = put_compact_string(buf, self.name);
196 } else {
197 let () = put_string(buf, self.name);
198 }
199 }
200 if version >= 0 {
201 put_i8(buf, self.mechanism);
202 }
203 if flex {
204 let tagged = WriteTaggedFields::new();
205 tagged.write(buf, &self.unknown_tagged_fields);
206 }
207 Ok(())
208 }
209 fn encoded_len(&self, version: i16) -> usize {
210 let flex = version >= 0;
211 let mut n: usize = 0;
212 if version >= 0 {
213 n += if flex {
214 compact_string_len(self.name)
215 } else {
216 string_len(self.name)
217 };
218 }
219 if version >= 0 {
220 n += 1;
221 }
222 if flex {
223 let known_pairs: Vec<(u32, usize)> = Vec::new();
224 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
225 }
226 n
227 }
228}
229impl<'de> DecodeBorrow<'de> for ScramCredentialDeletion<'de> {
230 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
231 let flex = version >= 0;
232 let mut out = Self::default();
233 if version >= 0 {
234 out.name = if flex {
235 get_compact_string_borrowed(buf)?
236 } else {
237 get_string_borrowed(buf)?
238 };
239 }
240 if version >= 0 {
241 out.mechanism = get_i8(buf)?;
242 }
243 if flex {
244 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
245 }
246 Ok(out)
247 }
248}
249#[cfg(test)]
250impl ScramCredentialDeletion<'_> {
251 #[must_use]
252 pub fn populated(version: i16) -> Self {
253 let mut m = Self::default();
254 if version >= 0 {
255 m.name = "x";
256 }
257 if version >= 0 {
258 m.mechanism = 1i8;
259 }
260 m
261 }
262}
263#[derive(Debug, Clone, PartialEq, Eq, Default)]
264pub struct ScramCredentialUpsertion<'a> {
265 pub name: &'a str,
266 pub mechanism: i8,
267 pub iterations: i32,
268 pub salt: &'a [u8],
269 pub salted_password: &'a [u8],
270 pub unknown_tagged_fields: UnknownTaggedFields,
271}
272impl ScramCredentialUpsertion<'_> {
273 #[must_use]
277 pub fn to_owned(
278 &self,
279 ) -> crate::owned::alter_user_scram_credentials_request::ScramCredentialUpsertion {
280 crate::owned::alter_user_scram_credentials_request::ScramCredentialUpsertion {
281 name: (self.name).to_string(),
282 mechanism: (self.mechanism),
283 iterations: (self.iterations),
284 salt: Bytes::copy_from_slice(self.salt),
285 salted_password: Bytes::copy_from_slice(self.salted_password),
286 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
287 }
288 }
289}
290impl Encode for ScramCredentialUpsertion<'_> {
291 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
292 let flex = version >= 0;
293 if version >= 0 {
294 if flex {
295 let () = put_compact_string(buf, self.name);
296 } else {
297 let () = put_string(buf, self.name);
298 }
299 }
300 if version >= 0 {
301 put_i8(buf, self.mechanism);
302 }
303 if version >= 0 {
304 put_i32(buf, self.iterations);
305 }
306 if version >= 0 {
307 if flex {
308 let () = put_compact_bytes(buf, self.salt);
309 } else {
310 let () = put_bytes(buf, self.salt);
311 }
312 }
313 if version >= 0 {
314 if flex {
315 let () = put_compact_bytes(buf, self.salted_password);
316 } else {
317 let () = put_bytes(buf, self.salted_password);
318 }
319 }
320 if flex {
321 let tagged = WriteTaggedFields::new();
322 tagged.write(buf, &self.unknown_tagged_fields);
323 }
324 Ok(())
325 }
326 fn encoded_len(&self, version: i16) -> usize {
327 let flex = version >= 0;
328 let mut n: usize = 0;
329 if version >= 0 {
330 n += if flex {
331 compact_string_len(self.name)
332 } else {
333 string_len(self.name)
334 };
335 }
336 if version >= 0 {
337 n += 1;
338 }
339 if version >= 0 {
340 n += 4;
341 }
342 if version >= 0 {
343 n += if flex {
344 crate::primitives::varint::uvarint_len(
345 u32::try_from((self.salt).len() + 1).unwrap(),
346 ) + (self.salt).len()
347 } else {
348 4 + (self.salt).len()
349 };
350 }
351 if version >= 0 {
352 n += if flex {
353 crate::primitives::varint::uvarint_len(
354 u32::try_from((self.salted_password).len() + 1).unwrap(),
355 ) + (self.salted_password).len()
356 } else {
357 4 + (self.salted_password).len()
358 };
359 }
360 if flex {
361 let known_pairs: Vec<(u32, usize)> = Vec::new();
362 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
363 }
364 n
365 }
366}
367impl<'de> DecodeBorrow<'de> for ScramCredentialUpsertion<'de> {
368 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
369 let flex = version >= 0;
370 let mut out = Self::default();
371 if version >= 0 {
372 out.name = if flex {
373 get_compact_string_borrowed(buf)?
374 } else {
375 get_string_borrowed(buf)?
376 };
377 }
378 if version >= 0 {
379 out.mechanism = get_i8(buf)?;
380 }
381 if version >= 0 {
382 out.iterations = get_i32(buf)?;
383 }
384 if version >= 0 {
385 out.salt = if flex {
386 get_compact_bytes_borrowed(buf)?
387 } else {
388 get_bytes_borrowed(buf)?
389 };
390 }
391 if version >= 0 {
392 out.salted_password = if flex {
393 get_compact_bytes_borrowed(buf)?
394 } else {
395 get_bytes_borrowed(buf)?
396 };
397 }
398 if flex {
399 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
400 }
401 Ok(out)
402 }
403}
404#[cfg(test)]
405impl ScramCredentialUpsertion<'_> {
406 #[must_use]
407 pub fn populated(version: i16) -> Self {
408 let mut m = Self::default();
409 if version >= 0 {
410 m.name = "x";
411 }
412 if version >= 0 {
413 m.mechanism = 1i8;
414 }
415 if version >= 0 {
416 m.iterations = 1i32;
417 }
418 if version >= 0 {
419 m.salt = &b"x"[..];
420 }
421 if version >= 0 {
422 m.salted_password = &b"x"[..];
423 }
424 m
425 }
426}