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_i32, get_i8, put_i32, put_i8};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned,
8    put_compact_string, put_string, string_len,
9};
10use crate::primitives::string_bytes::{bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes, put_compact_bytes};
11use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
12use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
13
14pub const API_KEY: i16 = 51;
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 0;
17pub const FLEXIBLE_MIN: i16 = 0;
18
19#[inline]
20fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
21
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub struct AlterUserScramCredentialsRequest {
24    pub deletions: Vec<ScramCredentialDeletion>,
25    pub upsertions: Vec<ScramCredentialUpsertion>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
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 { api_key: API_KEY, version });
33        }
34        let flex = is_flexible(version);
35        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.deletions).len(), flex); for it in &self.deletions { it.encode(buf, version)?; } } }
36        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.upsertions).len(), flex); for it in &self.upsertions { it.encode(buf, version)?; } } }
37        if flex {
38            let tagged = WriteTaggedFields::new();
39            tagged.write(buf, &self.unknown_tagged_fields);
40        }
41        Ok(())
42    }
43    fn encoded_len(&self, version: i16) -> usize {
44        let flex = is_flexible(version);
45        let mut n: usize = 0;
46        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.deletions).len(), flex); let body: usize = (self.deletions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
47        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.upsertions).len(), flex); let body: usize = (self.upsertions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
48        if flex {
49            let known_pairs: Vec<(u32, usize)> = Vec::new();
50            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
51        }
52        n
53    }
54}
55
56impl<'de> Decode<'de> for AlterUserScramCredentialsRequest {
57    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
58        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
59            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
60        }
61        let flex = is_flexible(version);
62        let mut out = Self::default();
63        if version >= 0 { out.deletions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ScramCredentialDeletion::decode(buf, version)?); } v }; }
64        if version >= 0 { out.upsertions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ScramCredentialUpsertion::decode(buf, version)?); } v }; }
65        if flex {
66            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
67                Ok(false)
68            })?;
69        }
70        Ok(out)
71    }
72}
73
74#[derive(Debug, Clone, PartialEq, Eq, Default)]
75pub struct ScramCredentialDeletion {
76    pub name: String,
77    pub mechanism: i8,
78    pub unknown_tagged_fields: UnknownTaggedFields,
79}
80
81impl Encode for ScramCredentialDeletion {
82    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
83        let flex = version >= 0;
84        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
85        if version >= 0 { put_i8(buf, self.mechanism) }
86        if flex {
87            let tagged = WriteTaggedFields::new();
88            tagged.write(buf, &self.unknown_tagged_fields);
89        }
90        Ok(())
91    }
92    fn encoded_len(&self, version: i16) -> usize {
93        let flex = version >= 0;
94        let mut n: usize = 0;
95        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
96        if version >= 0 { n += 1; }
97        if flex {
98            let known_pairs: Vec<(u32, usize)> = Vec::new();
99            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
100        }
101        n
102    }
103}
104
105impl<'de> Decode<'de> for ScramCredentialDeletion {
106    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
107        let flex = version >= 0;
108        let mut out = Self::default();
109        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
110        if version >= 0 { out.mechanism = get_i8(buf)?; }
111        if flex {
112            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
113                Ok(false)
114            })?;
115        }
116        Ok(out)
117    }
118}
119
120#[derive(Debug, Clone, PartialEq, Eq, Default)]
121pub struct ScramCredentialUpsertion {
122    pub name: String,
123    pub mechanism: i8,
124    pub iterations: i32,
125    pub salt: ::bytes::Bytes,
126    pub salted_password: ::bytes::Bytes,
127    pub unknown_tagged_fields: UnknownTaggedFields,
128}
129
130impl Encode for ScramCredentialUpsertion {
131    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
132        let flex = version >= 0;
133        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
134        if version >= 0 { put_i8(buf, self.mechanism) }
135        if version >= 0 { put_i32(buf, self.iterations) }
136        if version >= 0 { if flex { put_compact_bytes(buf, &self.salt) } else { put_bytes(buf, &self.salt) } }
137        if version >= 0 { if flex { put_compact_bytes(buf, &self.salted_password) } else { put_bytes(buf, &self.salted_password) } }
138        if flex {
139            let tagged = WriteTaggedFields::new();
140            tagged.write(buf, &self.unknown_tagged_fields);
141        }
142        Ok(())
143    }
144    fn encoded_len(&self, version: i16) -> usize {
145        let flex = version >= 0;
146        let mut n: usize = 0;
147        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
148        if version >= 0 { n += 1; }
149        if version >= 0 { n += 4; }
150        if version >= 0 { n += if flex { compact_bytes_len(&self.salt) } else { bytes_len(&self.salt) }; }
151        if version >= 0 { n += if flex { compact_bytes_len(&self.salted_password) } else { bytes_len(&self.salted_password) }; }
152        if flex {
153            let known_pairs: Vec<(u32, usize)> = Vec::new();
154            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
155        }
156        n
157    }
158}
159
160impl<'de> Decode<'de> for ScramCredentialUpsertion {
161    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
162        let flex = version >= 0;
163        let mut out = Self::default();
164        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
165        if version >= 0 { out.mechanism = get_i8(buf)?; }
166        if version >= 0 { out.iterations = get_i32(buf)?; }
167        if version >= 0 { out.salt = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
168        if version >= 0 { out.salted_password = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
169        if flex {
170            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
171                Ok(false)
172            })?;
173        }
174        Ok(out)
175    }
176}
177
178/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
179/// Only includes fields valid for the given version.
180#[must_use]
181#[allow(unused_comparisons)]
182pub fn default_json(version: i16) -> ::serde_json::Value {
183    let mut obj = ::serde_json::Map::new();
184    obj.insert("deletions".to_string(), ::serde_json::Value::Array(vec![]));
185    obj.insert("upsertions".to_string(), ::serde_json::Value::Array(vec![]));
186    ::serde_json::Value::Object(obj)
187}
188
189impl crate::ProtocolRequest for AlterUserScramCredentialsRequest {
190    const API_KEY: i16 = API_KEY;
191    const MIN_VERSION: i16 = MIN_VERSION;
192    const MAX_VERSION: i16 = MAX_VERSION;
193    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
194    type Response = super::alter_user_scram_credentials_response::AlterUserScramCredentialsResponse;
195}