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