Skip to main content

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

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