crabka_protocol/opt/rustwide/workdir/generated/
AlterClientQuotasResponse.owned.rs1use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
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, Eq, Default)]
21pub struct AlterClientQuotasResponse {
22 pub throttle_time_ms: i32,
23 pub entries: Vec<EntryData>,
24 pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Encode for AlterClientQuotasResponse {
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 put_i32(buf, self.throttle_time_ms);
37 }
38 if version >= 0 {
39 {
40 crate::primitives::array::put_array_len(buf, (self.entries).len(), flex);
41 for it in &self.entries {
42 it.encode(buf, version)?;
43 }
44 }
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 += 4;
57 }
58 if version >= 0 {
59 n += {
60 let prefix =
61 crate::primitives::array::array_len_prefix_len((self.entries).len(), flex);
62 let body: usize = (self.entries)
63 .iter()
64 .map(|it| it.encoded_len(version))
65 .sum();
66 prefix + body
67 };
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 AlterClientQuotasResponse {
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.throttle_time_ms = get_i32(buf)?;
88 }
89 if version >= 0 {
90 out.entries = {
91 let n = crate::primitives::array::get_array_len(buf, flex)?;
92 let mut v = Vec::with_capacity(n);
93 for _ in 0..n {
94 v.push(EntryData::decode(buf, version)?);
95 }
96 v
97 };
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 AlterClientQuotasResponse {
107 #[must_use]
108 pub fn populated(version: i16) -> Self {
109 let mut m = Self::default();
110 if version >= 0 {
111 m.throttle_time_ms = 1i32;
112 }
113 if version >= 0 {
114 m.entries = vec![EntryData::populated(version)];
115 }
116 m
117 }
118}
119#[derive(Debug, Clone, PartialEq, Eq, Default)]
120pub struct EntryData {
121 pub error_code: i16,
122 pub error_message: Option<String>,
123 pub entity: Vec<EntityData>,
124 pub unknown_tagged_fields: UnknownTaggedFields,
125}
126impl Encode for EntryData {
127 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
128 let flex = version >= 1;
129 if version >= 0 {
130 put_i16(buf, self.error_code);
131 }
132 if version >= 0 {
133 if flex {
134 put_compact_nullable_string(buf, self.error_message.as_deref());
135 } else {
136 put_nullable_string(buf, self.error_message.as_deref());
137 }
138 }
139 if version >= 0 {
140 {
141 crate::primitives::array::put_array_len(buf, (self.entity).len(), flex);
142 for it in &self.entity {
143 it.encode(buf, version)?;
144 }
145 }
146 }
147 if flex {
148 let tagged = WriteTaggedFields::new();
149 tagged.write(buf, &self.unknown_tagged_fields);
150 }
151 Ok(())
152 }
153 fn encoded_len(&self, version: i16) -> usize {
154 let flex = version >= 1;
155 let mut n: usize = 0;
156 if version >= 0 {
157 n += 2;
158 }
159 if version >= 0 {
160 n += if flex {
161 compact_nullable_string_len(self.error_message.as_deref())
162 } else {
163 nullable_string_len(self.error_message.as_deref())
164 };
165 }
166 if version >= 0 {
167 n += {
168 let prefix =
169 crate::primitives::array::array_len_prefix_len((self.entity).len(), flex);
170 let body: usize = (self.entity).iter().map(|it| it.encoded_len(version)).sum();
171 prefix + body
172 };
173 }
174 if flex {
175 let known_pairs: Vec<(u32, usize)> = Vec::new();
176 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
177 }
178 n
179 }
180}
181impl Decode<'_> for EntryData {
182 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
183 let flex = version >= 1;
184 let mut out = Self::default();
185 if version >= 0 {
186 out.error_code = get_i16(buf)?;
187 }
188 if version >= 0 {
189 out.error_message = if flex {
190 get_compact_nullable_string_owned(buf)?
191 } else {
192 get_nullable_string_owned(buf)?
193 };
194 }
195 if version >= 0 {
196 out.entity = {
197 let n = crate::primitives::array::get_array_len(buf, flex)?;
198 let mut v = Vec::with_capacity(n);
199 for _ in 0..n {
200 v.push(EntityData::decode(buf, version)?);
201 }
202 v
203 };
204 }
205 if flex {
206 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
207 }
208 Ok(out)
209 }
210}
211#[cfg(test)]
212impl EntryData {
213 #[must_use]
214 pub fn populated(version: i16) -> Self {
215 let mut m = Self::default();
216 if version >= 0 {
217 m.error_code = 1i16;
218 }
219 if version >= 0 {
220 m.error_message = Some("x".to_string());
221 }
222 if version >= 0 {
223 m.entity = vec![EntityData::populated(version)];
224 }
225 m
226 }
227}
228#[derive(Debug, Clone, PartialEq, Eq, Default)]
229pub struct EntityData {
230 pub entity_type: String,
231 pub entity_name: Option<String>,
232 pub unknown_tagged_fields: UnknownTaggedFields,
233}
234impl Encode for EntityData {
235 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
236 let flex = version >= 1;
237 if version >= 0 {
238 if flex {
239 put_compact_string(buf, &self.entity_type);
240 } else {
241 put_string(buf, &self.entity_type);
242 }
243 }
244 if version >= 0 {
245 if flex {
246 put_compact_nullable_string(buf, self.entity_name.as_deref());
247 } else {
248 put_nullable_string(buf, self.entity_name.as_deref());
249 }
250 }
251 if flex {
252 let tagged = WriteTaggedFields::new();
253 tagged.write(buf, &self.unknown_tagged_fields);
254 }
255 Ok(())
256 }
257 fn encoded_len(&self, version: i16) -> usize {
258 let flex = version >= 1;
259 let mut n: usize = 0;
260 if version >= 0 {
261 n += if flex {
262 compact_string_len(&self.entity_type)
263 } else {
264 string_len(&self.entity_type)
265 };
266 }
267 if version >= 0 {
268 n += if flex {
269 compact_nullable_string_len(self.entity_name.as_deref())
270 } else {
271 nullable_string_len(self.entity_name.as_deref())
272 };
273 }
274 if flex {
275 let known_pairs: Vec<(u32, usize)> = Vec::new();
276 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
277 }
278 n
279 }
280}
281impl Decode<'_> for EntityData {
282 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
283 let flex = version >= 1;
284 let mut out = Self::default();
285 if version >= 0 {
286 out.entity_type = if flex {
287 get_compact_string_owned(buf)?
288 } else {
289 get_string_owned(buf)?
290 };
291 }
292 if version >= 0 {
293 out.entity_name = if flex {
294 get_compact_nullable_string_owned(buf)?
295 } else {
296 get_nullable_string_owned(buf)?
297 };
298 }
299 if flex {
300 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
301 }
302 Ok(out)
303 }
304}
305#[cfg(test)]
306impl EntityData {
307 #[must_use]
308 pub fn populated(version: i16) -> Self {
309 let mut m = Self::default();
310 if version >= 0 {
311 m.entity_type = "x".to_string();
312 }
313 if version >= 0 {
314 m.entity_name = Some("x".to_string());
315 }
316 m
317 }
318}
319#[must_use]
322#[allow(unused_comparisons)]
323pub fn default_json(version: i16) -> ::serde_json::Value {
324 let mut obj = ::serde_json::Map::new();
325 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
326 obj.insert("entries".to_string(), ::serde_json::Value::Array(vec![]));
327 ::serde_json::Value::Object(obj)
328}