Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterUserScramCredentialsRequest.borrowed.rs

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