crabka_protocol/opt/rustwide/workdir/generated/
AlterClientQuotasRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_f64, put_bool, put_f64};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
10};
11use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
12use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
13
14pub const API_KEY: i16 = 49;
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 1;
17pub const FLEXIBLE_MIN: i16 = 1;
18
19#[inline]
20fn is_flexible(version: i16) -> bool {
21 version >= FLEXIBLE_MIN
22}
23
24#[derive(Debug, Clone, PartialEq, Default)]
25pub struct AlterClientQuotasRequest {
26 pub entries: Vec<EntryData>,
27 pub validate_only: bool,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for AlterClientQuotasRequest {
31 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33 return Err(ProtocolError::UnsupportedVersion {
34 api_key: API_KEY,
35 version,
36 });
37 }
38 let flex = is_flexible(version);
39 if version >= 0 {
40 {
41 crate::primitives::array::put_array_len(buf, (self.entries).len(), flex);
42 for it in &self.entries {
43 it.encode(buf, version)?;
44 }
45 }
46 }
47 if version >= 0 {
48 put_bool(buf, self.validate_only);
49 }
50 if flex {
51 let tagged = WriteTaggedFields::new();
52 tagged.write(buf, &self.unknown_tagged_fields);
53 }
54 Ok(())
55 }
56 fn encoded_len(&self, version: i16) -> usize {
57 let flex = is_flexible(version);
58 let mut n: usize = 0;
59 if version >= 0 {
60 n += {
61 let prefix =
62 crate::primitives::array::array_len_prefix_len((self.entries).len(), flex);
63 let body: usize = (self.entries)
64 .iter()
65 .map(|it| it.encoded_len(version))
66 .sum();
67 prefix + body
68 };
69 }
70 if version >= 0 {
71 n += 1;
72 }
73 if flex {
74 let known_pairs: Vec<(u32, usize)> = Vec::new();
75 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
76 }
77 n
78 }
79}
80impl Decode<'_> for AlterClientQuotasRequest {
81 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
82 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83 return Err(ProtocolError::UnsupportedVersion {
84 api_key: API_KEY,
85 version,
86 });
87 }
88 let flex = is_flexible(version);
89 let mut out = Self::default();
90 if version >= 0 {
91 out.entries = {
92 let n = crate::primitives::array::get_array_len(buf, flex)?;
93 let mut v = Vec::with_capacity(n);
94 for _ in 0..n {
95 v.push(EntryData::decode(buf, version)?);
96 }
97 v
98 };
99 }
100 if version >= 0 {
101 out.validate_only = get_bool(buf)?;
102 }
103 if flex {
104 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
105 }
106 Ok(out)
107 }
108}
109#[cfg(test)]
110impl AlterClientQuotasRequest {
111 #[must_use]
112 pub fn populated(version: i16) -> Self {
113 let mut m = Self::default();
114 if version >= 0 {
115 m.entries = vec![EntryData::populated(version)];
116 }
117 if version >= 0 {
118 m.validate_only = true;
119 }
120 m
121 }
122}
123#[derive(Debug, Clone, PartialEq, Default)]
124pub struct EntryData {
125 pub entity: Vec<EntityData>,
126 pub ops: Vec<OpData>,
127 pub unknown_tagged_fields: UnknownTaggedFields,
128}
129impl Encode for EntryData {
130 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
131 let flex = version >= 1;
132 if version >= 0 {
133 {
134 crate::primitives::array::put_array_len(buf, (self.entity).len(), flex);
135 for it in &self.entity {
136 it.encode(buf, version)?;
137 }
138 }
139 }
140 if version >= 0 {
141 {
142 crate::primitives::array::put_array_len(buf, (self.ops).len(), flex);
143 for it in &self.ops {
144 it.encode(buf, version)?;
145 }
146 }
147 }
148 if flex {
149 let tagged = WriteTaggedFields::new();
150 tagged.write(buf, &self.unknown_tagged_fields);
151 }
152 Ok(())
153 }
154 fn encoded_len(&self, version: i16) -> usize {
155 let flex = version >= 1;
156 let mut n: usize = 0;
157 if version >= 0 {
158 n += {
159 let prefix =
160 crate::primitives::array::array_len_prefix_len((self.entity).len(), flex);
161 let body: usize = (self.entity).iter().map(|it| it.encoded_len(version)).sum();
162 prefix + body
163 };
164 }
165 if version >= 0 {
166 n += {
167 let prefix = crate::primitives::array::array_len_prefix_len((self.ops).len(), flex);
168 let body: usize = (self.ops).iter().map(|it| it.encoded_len(version)).sum();
169 prefix + body
170 };
171 }
172 if flex {
173 let known_pairs: Vec<(u32, usize)> = Vec::new();
174 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
175 }
176 n
177 }
178}
179impl Decode<'_> for EntryData {
180 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
181 let flex = version >= 1;
182 let mut out = Self::default();
183 if version >= 0 {
184 out.entity = {
185 let n = crate::primitives::array::get_array_len(buf, flex)?;
186 let mut v = Vec::with_capacity(n);
187 for _ in 0..n {
188 v.push(EntityData::decode(buf, version)?);
189 }
190 v
191 };
192 }
193 if version >= 0 {
194 out.ops = {
195 let n = crate::primitives::array::get_array_len(buf, flex)?;
196 let mut v = Vec::with_capacity(n);
197 for _ in 0..n {
198 v.push(OpData::decode(buf, version)?);
199 }
200 v
201 };
202 }
203 if flex {
204 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
205 }
206 Ok(out)
207 }
208}
209#[cfg(test)]
210impl EntryData {
211 #[must_use]
212 pub fn populated(version: i16) -> Self {
213 let mut m = Self::default();
214 if version >= 0 {
215 m.entity = vec![EntityData::populated(version)];
216 }
217 if version >= 0 {
218 m.ops = vec![OpData::populated(version)];
219 }
220 m
221 }
222}
223#[derive(Debug, Clone, PartialEq, Eq, Default)]
224pub struct EntityData {
225 pub entity_type: String,
226 pub entity_name: Option<String>,
227 pub unknown_tagged_fields: UnknownTaggedFields,
228}
229impl Encode for EntityData {
230 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
231 let flex = version >= 1;
232 if version >= 0 {
233 if flex {
234 put_compact_string(buf, &self.entity_type);
235 } else {
236 put_string(buf, &self.entity_type);
237 }
238 }
239 if version >= 0 {
240 if flex {
241 put_compact_nullable_string(buf, self.entity_name.as_deref());
242 } else {
243 put_nullable_string(buf, self.entity_name.as_deref());
244 }
245 }
246 if flex {
247 let tagged = WriteTaggedFields::new();
248 tagged.write(buf, &self.unknown_tagged_fields);
249 }
250 Ok(())
251 }
252 fn encoded_len(&self, version: i16) -> usize {
253 let flex = version >= 1;
254 let mut n: usize = 0;
255 if version >= 0 {
256 n += if flex {
257 compact_string_len(&self.entity_type)
258 } else {
259 string_len(&self.entity_type)
260 };
261 }
262 if version >= 0 {
263 n += if flex {
264 compact_nullable_string_len(self.entity_name.as_deref())
265 } else {
266 nullable_string_len(self.entity_name.as_deref())
267 };
268 }
269 if flex {
270 let known_pairs: Vec<(u32, usize)> = Vec::new();
271 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
272 }
273 n
274 }
275}
276impl Decode<'_> for EntityData {
277 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
278 let flex = version >= 1;
279 let mut out = Self::default();
280 if version >= 0 {
281 out.entity_type = if flex {
282 get_compact_string_owned(buf)?
283 } else {
284 get_string_owned(buf)?
285 };
286 }
287 if version >= 0 {
288 out.entity_name = if flex {
289 get_compact_nullable_string_owned(buf)?
290 } else {
291 get_nullable_string_owned(buf)?
292 };
293 }
294 if flex {
295 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
296 }
297 Ok(out)
298 }
299}
300#[cfg(test)]
301impl EntityData {
302 #[must_use]
303 pub fn populated(version: i16) -> Self {
304 let mut m = Self::default();
305 if version >= 0 {
306 m.entity_type = "x".to_string();
307 }
308 if version >= 0 {
309 m.entity_name = Some("x".to_string());
310 }
311 m
312 }
313}
314#[derive(Debug, Clone, PartialEq, Default)]
315pub struct OpData {
316 pub key: String,
317 pub value: f64,
318 pub remove: bool,
319 pub unknown_tagged_fields: UnknownTaggedFields,
320}
321impl Encode for OpData {
322 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
323 let flex = version >= 1;
324 if version >= 0 {
325 if flex {
326 put_compact_string(buf, &self.key);
327 } else {
328 put_string(buf, &self.key);
329 }
330 }
331 if version >= 0 {
332 put_f64(buf, self.value);
333 }
334 if version >= 0 {
335 put_bool(buf, self.remove);
336 }
337 if flex {
338 let tagged = WriteTaggedFields::new();
339 tagged.write(buf, &self.unknown_tagged_fields);
340 }
341 Ok(())
342 }
343 fn encoded_len(&self, version: i16) -> usize {
344 let flex = version >= 1;
345 let mut n: usize = 0;
346 if version >= 0 {
347 n += if flex {
348 compact_string_len(&self.key)
349 } else {
350 string_len(&self.key)
351 };
352 }
353 if version >= 0 {
354 n += 8;
355 }
356 if version >= 0 {
357 n += 1;
358 }
359 if flex {
360 let known_pairs: Vec<(u32, usize)> = Vec::new();
361 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
362 }
363 n
364 }
365}
366impl Decode<'_> for OpData {
367 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
368 let flex = version >= 1;
369 let mut out = Self::default();
370 if version >= 0 {
371 out.key = if flex {
372 get_compact_string_owned(buf)?
373 } else {
374 get_string_owned(buf)?
375 };
376 }
377 if version >= 0 {
378 out.value = get_f64(buf)?;
379 }
380 if version >= 0 {
381 out.remove = get_bool(buf)?;
382 }
383 if flex {
384 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
385 }
386 Ok(out)
387 }
388}
389#[cfg(test)]
390impl OpData {
391 #[must_use]
392 pub fn populated(version: i16) -> Self {
393 let mut m = Self::default();
394 if version >= 0 {
395 m.key = "x".to_string();
396 }
397 if version >= 0 {
398 m.value = 1.0f64;
399 }
400 if version >= 0 {
401 m.remove = true;
402 }
403 m
404 }
405}
406
407#[must_use]
410#[allow(unused_comparisons)]
411pub fn default_json(version: i16) -> ::serde_json::Value {
412 let mut obj = ::serde_json::Map::new();
413 obj.insert("entries".to_string(), ::serde_json::Value::Array(vec![]));
414 obj.insert("validateOnly".to_string(), ::serde_json::Value::Bool(false));
415 ::serde_json::Value::Object(obj)
416}
417
418impl crate::ProtocolRequest for AlterClientQuotasRequest {
419 const API_KEY: i16 = API_KEY;
420 const MIN_VERSION: i16 = MIN_VERSION;
421 const MAX_VERSION: i16 = MAX_VERSION;
422 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
423 type Response = super::alter_client_quotas_response::AlterClientQuotasResponse;
424}