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