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