Skip to main content

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

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