krabka_protocol/opt/rustwide/workdir/generated/
AlterClientQuotasResponse.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 = 49;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 1;
21pub const FLEXIBLE_MIN: i16 = 1;
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 AlterClientQuotasResponse {
29 pub throttle_time_ms: i32,
30 pub entries: Vec<EntryData>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for AlterClientQuotasResponse {
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.entries).len(), flex);
48 for it in &self.entries {
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.entries).len(), flex);
69 let body: usize = (self.entries)
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 AlterClientQuotasResponse {
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.entries = {
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(EntryData::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 AlterClientQuotasResponse {
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.entries = vec![EntryData::populated(version)];
122 }
123 m
124 }
125}
126#[derive(Debug, Clone, PartialEq, Eq)]
127pub struct EntryData {
128 pub error_code: i16,
129 pub error_message: Option<String>,
130 pub entity: Vec<EntityData>,
131 pub unknown_tagged_fields: UnknownTaggedFields,
132}
133impl Default for EntryData {
134 fn default() -> Self {
135 Self {
136 error_code: 0i16,
137 error_message: Some(String::new()),
138 entity: Vec::new(),
139 unknown_tagged_fields: UnknownTaggedFields::default(),
140 }
141 }
142}
143impl Encode for EntryData {
144 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
145 let flex = version >= 1;
146 if version >= 0 {
147 put_i16(buf, self.error_code);
148 }
149 if version >= 0 {
150 if flex {
151 let () = put_compact_nullable_string(buf, self.error_message.as_deref());
152 } else {
153 let () = put_nullable_string(buf, self.error_message.as_deref());
154 }
155 }
156 if version >= 0 {
157 {
158 crate::primitives::array::put_array_len(buf, (self.entity).len(), flex);
159 for it in &self.entity {
160 it.encode(buf, version)?;
161 }
162 };
163 }
164 if flex {
165 let tagged = WriteTaggedFields::new();
166 tagged.write(buf, &self.unknown_tagged_fields);
167 }
168 Ok(())
169 }
170 fn encoded_len(&self, version: i16) -> usize {
171 let flex = version >= 1;
172 let mut n: usize = 0;
173 if version >= 0 {
174 n += 2;
175 }
176 if version >= 0 {
177 n += if flex {
178 compact_nullable_string_len(self.error_message.as_deref())
179 } else {
180 nullable_string_len(self.error_message.as_deref())
181 };
182 }
183 if version >= 0 {
184 n += {
185 let prefix =
186 crate::primitives::array::array_len_prefix_len((self.entity).len(), flex);
187 let body: usize = (self.entity).iter().map(|it| it.encoded_len(version)).sum();
188 prefix + body
189 };
190 }
191 if flex {
192 let known_pairs: Vec<(u32, usize)> = Vec::new();
193 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
194 }
195 n
196 }
197}
198impl Decode<'_> for EntryData {
199 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
200 let flex = version >= 1;
201 let mut out = Self::default();
202 if version >= 0 {
203 out.error_code = get_i16(buf)?;
204 }
205 if version >= 0 {
206 out.error_message = if flex {
207 get_compact_nullable_string_owned(buf)?
208 } else {
209 get_nullable_string_owned(buf)?
210 };
211 }
212 if version >= 0 {
213 out.entity = {
214 let n = crate::primitives::array::get_array_len(buf, flex)?;
215 let mut v = Vec::with_capacity(n);
216 for _ in 0..n {
217 v.push(EntityData::decode(buf, version)?);
218 }
219 v
220 };
221 }
222 if flex {
223 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
224 }
225 Ok(out)
226 }
227}
228#[cfg(test)]
229impl EntryData {
230 #[must_use]
231 pub fn populated(version: i16) -> Self {
232 let mut m = Self::default();
233 if version >= 0 {
234 m.error_code = 1i16;
235 }
236 if version >= 0 {
237 m.error_message = Some("x".to_string());
238 }
239 if version >= 0 {
240 m.entity = vec![EntityData::populated(version)];
241 }
242 m
243 }
244}
245#[derive(Debug, Clone, PartialEq, Eq)]
246pub struct EntityData {
247 pub entity_type: String,
248 pub entity_name: Option<String>,
249 pub unknown_tagged_fields: UnknownTaggedFields,
250}
251impl Default for EntityData {
252 fn default() -> Self {
253 Self {
254 entity_type: String::new(),
255 entity_name: Some(String::new()),
256 unknown_tagged_fields: UnknownTaggedFields::default(),
257 }
258 }
259}
260impl Encode for EntityData {
261 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
262 let flex = version >= 1;
263 if version >= 0 {
264 if flex {
265 let () = put_compact_string(buf, &self.entity_type);
266 } else {
267 let () = put_string(buf, &self.entity_type);
268 }
269 }
270 if version >= 0 {
271 if flex {
272 let () = put_compact_nullable_string(buf, self.entity_name.as_deref());
273 } else {
274 let () = put_nullable_string(buf, self.entity_name.as_deref());
275 }
276 }
277 if flex {
278 let tagged = WriteTaggedFields::new();
279 tagged.write(buf, &self.unknown_tagged_fields);
280 }
281 Ok(())
282 }
283 fn encoded_len(&self, version: i16) -> usize {
284 let flex = version >= 1;
285 let mut n: usize = 0;
286 if version >= 0 {
287 n += if flex {
288 compact_string_len(&self.entity_type)
289 } else {
290 string_len(&self.entity_type)
291 };
292 }
293 if version >= 0 {
294 n += if flex {
295 compact_nullable_string_len(self.entity_name.as_deref())
296 } else {
297 nullable_string_len(self.entity_name.as_deref())
298 };
299 }
300 if flex {
301 let known_pairs: Vec<(u32, usize)> = Vec::new();
302 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
303 }
304 n
305 }
306}
307impl Decode<'_> for EntityData {
308 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
309 let flex = version >= 1;
310 let mut out = Self::default();
311 if version >= 0 {
312 out.entity_type = if flex {
313 get_compact_string_owned(buf)?
314 } else {
315 get_string_owned(buf)?
316 };
317 }
318 if version >= 0 {
319 out.entity_name = if flex {
320 get_compact_nullable_string_owned(buf)?
321 } else {
322 get_nullable_string_owned(buf)?
323 };
324 }
325 if flex {
326 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
327 }
328 Ok(out)
329 }
330}
331#[cfg(test)]
332impl EntityData {
333 #[must_use]
334 pub fn populated(version: i16) -> Self {
335 let mut m = Self::default();
336 if version >= 0 {
337 m.entity_type = "x".to_string();
338 }
339 if version >= 0 {
340 m.entity_name = Some("x".to_string());
341 }
342 m
343 }
344}
345#[must_use]
348#[allow(unused_comparisons)]
349pub fn default_json(_version: i16) -> ::serde_json::Value {
350 let mut obj = ::serde_json::Map::new();
351 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
352 obj.insert("entries".to_string(), ::serde_json::Value::Array(vec![]));
353 ::serde_json::Value::Object(obj)
354}