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