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