Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
3use crate::primitives::string_bytes::{
4    compact_nullable_string_len, compact_string_len, nullable_string_len,
5    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
6};
7use crate::primitives::string_bytes_borrowed::{
8    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
9    get_nullable_string_borrowed, get_string_borrowed,
10};
11use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
12use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
13use bytes::BufMut;
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#[inline]
19fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub struct AlterUserScramCredentialsResponse<'a> {
24    pub throttle_time_ms: i32,
25    pub results: Vec<AlterUserScramCredentialsResult<'a>>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl AlterUserScramCredentialsResponse<'_> {
29    pub fn to_owned(
30        &self,
31    ) -> crate::owned::alter_user_scram_credentials_response::AlterUserScramCredentialsResponse
32    {
33        crate::owned::alter_user_scram_credentials_response::AlterUserScramCredentialsResponse {
34            throttle_time_ms: (self.throttle_time_ms),
35            results: (self.results)
36                .iter()
37                .map(AlterUserScramCredentialsResult::to_owned)
38                .collect(),
39            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
40        }
41    }
42}
43impl Encode for AlterUserScramCredentialsResponse<'_> {
44    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
45        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
46            return Err(ProtocolError::UnsupportedVersion {
47                api_key: API_KEY,
48                version,
49            });
50        }
51        let flex = is_flexible(version);
52        if version >= 0 {
53            put_i32(buf, self.throttle_time_ms);
54        }
55        if version >= 0 {
56            {
57                crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
58                for it in &self.results {
59                    it.encode(buf, version)?;
60                }
61            }
62        }
63        if flex {
64            let tagged = WriteTaggedFields::new();
65            tagged.write(buf, &self.unknown_tagged_fields);
66        }
67        Ok(())
68    }
69    fn encoded_len(&self, version: i16) -> usize {
70        let flex = is_flexible(version);
71        let mut n: usize = 0;
72        if version >= 0 {
73            n += 4;
74        }
75        if version >= 0 {
76            n += {
77                let prefix =
78                    crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
79                let body: usize = (self.results)
80                    .iter()
81                    .map(|it| it.encoded_len(version))
82                    .sum();
83                prefix + body
84            };
85        }
86        if flex {
87            let known_pairs: Vec<(u32, usize)> = Vec::new();
88            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
89        }
90        n
91    }
92}
93impl<'de> DecodeBorrow<'de> for AlterUserScramCredentialsResponse<'de> {
94    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
95        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
96            return Err(ProtocolError::UnsupportedVersion {
97                api_key: API_KEY,
98                version,
99            });
100        }
101        let flex = is_flexible(version);
102        let mut out = Self::default();
103        if version >= 0 {
104            out.throttle_time_ms = get_i32(buf)?;
105        }
106        if version >= 0 {
107            out.results = {
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(AlterUserScramCredentialsResult::decode_borrow(
112                        buf, version,
113                    )?);
114                }
115                v
116            };
117        }
118        if flex {
119            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
120        }
121        Ok(out)
122    }
123}
124#[cfg(test)]
125impl AlterUserScramCredentialsResponse<'_> {
126    #[must_use]
127    pub fn populated(version: i16) -> Self {
128        let mut m = Self::default();
129        if version >= 0 {
130            m.throttle_time_ms = 1i32;
131        }
132        if version >= 0 {
133            m.results = vec![AlterUserScramCredentialsResult::populated(version)];
134        }
135        m
136    }
137}
138#[derive(Debug, Clone, PartialEq, Eq, Default)]
139pub struct AlterUserScramCredentialsResult<'a> {
140    pub user: &'a str,
141    pub error_code: i16,
142    pub error_message: Option<&'a str>,
143    pub unknown_tagged_fields: UnknownTaggedFields,
144}
145impl AlterUserScramCredentialsResult<'_> {
146    pub fn to_owned(
147        &self,
148    ) -> crate::owned::alter_user_scram_credentials_response::AlterUserScramCredentialsResult {
149        crate::owned::alter_user_scram_credentials_response::AlterUserScramCredentialsResult {
150            user: (self.user).to_string(),
151            error_code: (self.error_code),
152            error_message: (self.error_message).map(std::string::ToString::to_string),
153            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
154        }
155    }
156}
157impl Encode for AlterUserScramCredentialsResult<'_> {
158    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
159        let flex = version >= 0;
160        if version >= 0 {
161            if flex {
162                put_compact_string(buf, self.user);
163            } else {
164                put_string(buf, self.user);
165            }
166        }
167        if version >= 0 {
168            put_i16(buf, self.error_code);
169        }
170        if version >= 0 {
171            if flex {
172                put_compact_nullable_string(buf, self.error_message);
173            } else {
174                put_nullable_string(buf, self.error_message);
175            }
176        }
177        if flex {
178            let tagged = WriteTaggedFields::new();
179            tagged.write(buf, &self.unknown_tagged_fields);
180        }
181        Ok(())
182    }
183    fn encoded_len(&self, version: i16) -> usize {
184        let flex = version >= 0;
185        let mut n: usize = 0;
186        if version >= 0 {
187            n += if flex {
188                compact_string_len(self.user)
189            } else {
190                string_len(self.user)
191            };
192        }
193        if version >= 0 {
194            n += 2;
195        }
196        if version >= 0 {
197            n += if flex {
198                compact_nullable_string_len(self.error_message)
199            } else {
200                nullable_string_len(self.error_message)
201            };
202        }
203        if flex {
204            let known_pairs: Vec<(u32, usize)> = Vec::new();
205            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
206        }
207        n
208    }
209}
210impl<'de> DecodeBorrow<'de> for AlterUserScramCredentialsResult<'de> {
211    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
212        let flex = version >= 0;
213        let mut out = Self::default();
214        if version >= 0 {
215            out.user = if flex {
216                get_compact_string_borrowed(buf)?
217            } else {
218                get_string_borrowed(buf)?
219            };
220        }
221        if version >= 0 {
222            out.error_code = get_i16(buf)?;
223        }
224        if version >= 0 {
225            out.error_message = if flex {
226                get_compact_nullable_string_borrowed(buf)?
227            } else {
228                get_nullable_string_borrowed(buf)?
229            };
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 AlterUserScramCredentialsResult<'_> {
239    #[must_use]
240    pub fn populated(version: i16) -> Self {
241        let mut m = Self::default();
242        if version >= 0 {
243            m.user = "x";
244        }
245        if version >= 0 {
246            m.error_code = 1i16;
247        }
248        if version >= 0 {
249            m.error_message = Some("x");
250        }
251        m
252    }
253}