Skip to main content

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

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