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