krabka_protocol/opt/rustwide/workdir/generated/
AlterClientQuotasResponse.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_i16, get_i32, put_i16, put_i32},
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 FLEXIBLE_MIN: i16 = 1;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26 version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq, Default)]
29pub struct AlterClientQuotasResponse {
30 pub throttle_time_ms: i32,
31 pub entries: Vec<EntryData>,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for AlterClientQuotasResponse {
35 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37 return Err(ProtocolError::UnsupportedVersion {
38 api_key: API_KEY,
39 version,
40 });
41 }
42 let flex = is_flexible(version);
43 if version >= 0 {
44 put_i32(buf, self.throttle_time_ms);
45 }
46 if version >= 0 {
47 {
48 put_array_len(buf, (self.entries).len(), flex)?;
49 for it in &self.entries {
50 it.encode(buf, version)?;
51 }
52 }
53 }
54 if flex {
55 let tagged = WriteTaggedFields::new();
56 tagged.write(buf, &self.unknown_tagged_fields)?;
57 }
58 Ok(())
59 }
60 fn encoded_len(&self, version: i16) -> usize {
61 let flex = is_flexible(version);
62 let mut n: usize = 0;
63 if version >= 0 {
64 n += 4;
65 }
66 if version >= 0 {
67 n += {
68 let prefix = 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 = 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 put_compact_nullable_string(buf, self.error_message.as_deref())?;
152 } else {
153 put_nullable_string(buf, self.error_message.as_deref())?;
154 }
155 }
156 if version >= 0 {
157 {
158 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 = array_len_prefix_len((self.entity).len(), flex);
186 let body: usize = (self.entity).iter().map(|it| it.encoded_len(version)).sum();
187 prefix + body
188 };
189 }
190 if flex {
191 let known_pairs: Vec<(u32, usize)> = Vec::new();
192 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
193 }
194 n
195 }
196}
197impl Decode<'_> for EntryData {
198 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
199 let flex = version >= 1;
200 let mut out = Self::default();
201 if version >= 0 {
202 out.error_code = get_i16(buf)?;
203 }
204 if version >= 0 {
205 out.error_message = if flex {
206 get_compact_nullable_string_owned(buf)?
207 } else {
208 get_nullable_string_owned(buf)?
209 };
210 }
211 if version >= 0 {
212 out.entity = {
213 let n = get_array_len(buf, flex)?;
214 let mut v = Vec::with_capacity(n);
215 for _ in 0..n {
216 v.push(EntityData::decode(buf, version)?);
217 }
218 v
219 };
220 }
221 if flex {
222 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
223 }
224 Ok(out)
225 }
226}
227#[cfg(test)]
228impl EntryData {
229 #[must_use]
230 pub fn populated(version: i16) -> Self {
231 let mut m = Self::default();
232 if version >= 0 {
233 m.error_code = 1i16;
234 }
235 if version >= 0 {
236 m.error_message = Some("x".to_owned());
237 }
238 if version >= 0 {
239 m.entity = vec![EntityData::populated(version)];
240 }
241 m
242 }
243}
244#[derive(Debug, Clone, PartialEq, Eq)]
245pub struct EntityData {
246 pub entity_type: String,
247 pub entity_name: Option<String>,
248 pub unknown_tagged_fields: UnknownTaggedFields,
249}
250impl Default for EntityData {
251 fn default() -> Self {
252 Self {
253 entity_type: String::new(),
254 entity_name: Some(String::new()),
255 unknown_tagged_fields: UnknownTaggedFields::default(),
256 }
257 }
258}
259impl Encode for EntityData {
260 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
261 let flex = version >= 1;
262 if version >= 0 {
263 if flex {
264 put_compact_string(buf, &self.entity_type)?;
265 } else {
266 put_string(buf, &self.entity_type)?;
267 }
268 }
269 if version >= 0 {
270 if flex {
271 put_compact_nullable_string(buf, self.entity_name.as_deref())?;
272 } else {
273 put_nullable_string(buf, self.entity_name.as_deref())?;
274 }
275 }
276 if flex {
277 let tagged = WriteTaggedFields::new();
278 tagged.write(buf, &self.unknown_tagged_fields)?;
279 }
280 Ok(())
281 }
282 fn encoded_len(&self, version: i16) -> usize {
283 let flex = version >= 1;
284 let mut n: usize = 0;
285 if version >= 0 {
286 n += if flex {
287 compact_string_len(&self.entity_type)
288 } else {
289 string_len(&self.entity_type)
290 };
291 }
292 if version >= 0 {
293 n += if flex {
294 compact_nullable_string_len(self.entity_name.as_deref())
295 } else {
296 nullable_string_len(self.entity_name.as_deref())
297 };
298 }
299 if flex {
300 let known_pairs: Vec<(u32, usize)> = Vec::new();
301 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
302 }
303 n
304 }
305}
306impl Decode<'_> for EntityData {
307 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
308 let flex = version >= 1;
309 let mut out = Self::default();
310 if version >= 0 {
311 out.entity_type = if flex {
312 get_compact_string_owned(buf)?
313 } else {
314 get_string_owned(buf)?
315 };
316 }
317 if version >= 0 {
318 out.entity_name = if flex {
319 get_compact_nullable_string_owned(buf)?
320 } else {
321 get_nullable_string_owned(buf)?
322 };
323 }
324 if flex {
325 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
326 }
327 Ok(out)
328 }
329}
330#[cfg(test)]
331impl EntityData {
332 #[must_use]
333 pub fn populated(version: i16) -> Self {
334 let mut m = Self::default();
335 if version >= 0 {
336 m.entity_type = "x".to_owned();
337 }
338 if version >= 0 {
339 m.entity_name = Some("x".to_owned());
340 }
341 m
342 }
343}
344#[must_use]
347#[allow(unused_comparisons)]
348pub fn default_json(_version: i16) -> ::serde_json::Value {
349 let mut obj = ::serde_json::Map::new();
350 obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
351 obj.insert("entries".to_owned(), ::serde_json::Value::Array(vec![]));
352 ::serde_json::Value::Object(obj)
353}