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