crabka_protocol/opt/rustwide/workdir/generated/
DescribeLogDirsResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{
6 get_bool, get_i16, get_i32, get_i64, put_bool, put_i16, put_i32, put_i64,
7};
8use crate::primitives::string_bytes::{
9 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
10 string_len,
11};
12use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 35;
16pub const MIN_VERSION: i16 = 1;
17pub const MAX_VERSION: i16 = 5;
18pub const FLEXIBLE_MIN: i16 = 2;
19
20#[inline]
21fn is_flexible(version: i16) -> bool {
22 version >= FLEXIBLE_MIN
23}
24
25#[derive(Debug, Clone, PartialEq, Eq, Default)]
26pub struct DescribeLogDirsResponse {
27 pub throttle_time_ms: i32,
28 pub error_code: i16,
29 pub results: Vec<DescribeLogDirsResult>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for DescribeLogDirsResponse {
33 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35 return Err(ProtocolError::UnsupportedVersion {
36 api_key: API_KEY,
37 version,
38 });
39 }
40 let flex = is_flexible(version);
41 if version >= 0 {
42 put_i32(buf, self.throttle_time_ms);
43 }
44 if version >= 3 {
45 put_i16(buf, self.error_code);
46 }
47 if version >= 0 {
48 {
49 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
50 for it in &self.results {
51 it.encode(buf, version)?;
52 }
53 }
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 += 4;
66 }
67 if version >= 3 {
68 n += 2;
69 }
70 if version >= 0 {
71 n += {
72 let prefix =
73 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
74 let body: usize = (self.results)
75 .iter()
76 .map(|it| it.encoded_len(version))
77 .sum();
78 prefix + body
79 };
80 }
81 if flex {
82 let known_pairs: Vec<(u32, usize)> = Vec::new();
83 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
84 }
85 n
86 }
87}
88impl Decode<'_> for DescribeLogDirsResponse {
89 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
90 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
91 return Err(ProtocolError::UnsupportedVersion {
92 api_key: API_KEY,
93 version,
94 });
95 }
96 let flex = is_flexible(version);
97 let mut out = Self::default();
98 if version >= 0 {
99 out.throttle_time_ms = get_i32(buf)?;
100 }
101 if version >= 3 {
102 out.error_code = get_i16(buf)?;
103 }
104 if version >= 0 {
105 out.results = {
106 let n = crate::primitives::array::get_array_len(buf, flex)?;
107 let mut v = Vec::with_capacity(n);
108 for _ in 0..n {
109 v.push(DescribeLogDirsResult::decode(buf, version)?);
110 }
111 v
112 };
113 }
114 if flex {
115 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
116 }
117 Ok(out)
118 }
119}
120#[cfg(test)]
121impl DescribeLogDirsResponse {
122 #[must_use]
123 pub fn populated(version: i16) -> Self {
124 let mut m = Self::default();
125 if version >= 0 {
126 m.throttle_time_ms = 1i32;
127 }
128 if version >= 3 {
129 m.error_code = 1i16;
130 }
131 if version >= 0 {
132 m.results = vec![DescribeLogDirsResult::populated(version)];
133 }
134 m
135 }
136}
137#[derive(Debug, Clone, PartialEq, Eq)]
138pub struct DescribeLogDirsResult {
139 pub error_code: i16,
140 pub log_dir: String,
141 pub topics: Vec<DescribeLogDirsTopic>,
142 pub total_bytes: i64,
143 pub usable_bytes: i64,
144 pub is_cordoned: bool,
145 pub unknown_tagged_fields: UnknownTaggedFields,
146}
147impl Default for DescribeLogDirsResult {
148 fn default() -> Self {
149 Self {
150 error_code: 0i16,
151 log_dir: String::new(),
152 topics: Vec::new(),
153 total_bytes: -1i64,
154 usable_bytes: -1i64,
155 is_cordoned: false,
156 unknown_tagged_fields: Default::default(),
157 }
158 }
159}
160impl Encode for DescribeLogDirsResult {
161 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
162 let flex = version >= 2;
163 if version >= 0 {
164 put_i16(buf, self.error_code);
165 }
166 if version >= 0 {
167 if flex {
168 put_compact_string(buf, &self.log_dir);
169 } else {
170 put_string(buf, &self.log_dir);
171 }
172 }
173 if version >= 0 {
174 {
175 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
176 for it in &self.topics {
177 it.encode(buf, version)?;
178 }
179 }
180 }
181 if version >= 4 {
182 put_i64(buf, self.total_bytes);
183 }
184 if version >= 4 {
185 put_i64(buf, self.usable_bytes);
186 }
187 if version >= 5 {
188 put_bool(buf, self.is_cordoned);
189 }
190 if flex {
191 let tagged = WriteTaggedFields::new();
192 tagged.write(buf, &self.unknown_tagged_fields);
193 }
194 Ok(())
195 }
196 fn encoded_len(&self, version: i16) -> usize {
197 let flex = version >= 2;
198 let mut n: usize = 0;
199 if version >= 0 {
200 n += 2;
201 }
202 if version >= 0 {
203 n += if flex {
204 compact_string_len(&self.log_dir)
205 } else {
206 string_len(&self.log_dir)
207 };
208 }
209 if version >= 0 {
210 n += {
211 let prefix =
212 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
213 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
214 prefix + body
215 };
216 }
217 if version >= 4 {
218 n += 8;
219 }
220 if version >= 4 {
221 n += 8;
222 }
223 if version >= 5 {
224 n += 1;
225 }
226 if flex {
227 let known_pairs: Vec<(u32, usize)> = Vec::new();
228 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
229 }
230 n
231 }
232}
233impl Decode<'_> for DescribeLogDirsResult {
234 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
235 let flex = version >= 2;
236 let mut out = Self::default();
237 if version >= 0 {
238 out.error_code = get_i16(buf)?;
239 }
240 if version >= 0 {
241 out.log_dir = if flex {
242 get_compact_string_owned(buf)?
243 } else {
244 get_string_owned(buf)?
245 };
246 }
247 if version >= 0 {
248 out.topics = {
249 let n = crate::primitives::array::get_array_len(buf, flex)?;
250 let mut v = Vec::with_capacity(n);
251 for _ in 0..n {
252 v.push(DescribeLogDirsTopic::decode(buf, version)?);
253 }
254 v
255 };
256 }
257 if version >= 4 {
258 out.total_bytes = get_i64(buf)?;
259 }
260 if version >= 4 {
261 out.usable_bytes = get_i64(buf)?;
262 }
263 if version >= 5 {
264 out.is_cordoned = get_bool(buf)?;
265 }
266 if flex {
267 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
268 }
269 Ok(out)
270 }
271}
272#[cfg(test)]
273impl DescribeLogDirsResult {
274 #[must_use]
275 pub fn populated(version: i16) -> Self {
276 let mut m = Self::default();
277 if version >= 0 {
278 m.error_code = 1i16;
279 }
280 if version >= 0 {
281 m.log_dir = "x".to_string();
282 }
283 if version >= 0 {
284 m.topics = vec![DescribeLogDirsTopic::populated(version)];
285 }
286 if version >= 4 {
287 m.total_bytes = 1i64;
288 }
289 if version >= 4 {
290 m.usable_bytes = 1i64;
291 }
292 if version >= 5 {
293 m.is_cordoned = true;
294 }
295 m
296 }
297}
298#[derive(Debug, Clone, PartialEq, Eq, Default)]
299pub struct DescribeLogDirsTopic {
300 pub name: String,
301 pub partitions: Vec<DescribeLogDirsPartition>,
302 pub unknown_tagged_fields: UnknownTaggedFields,
303}
304impl Encode for DescribeLogDirsTopic {
305 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
306 let flex = version >= 2;
307 if version >= 0 {
308 if flex {
309 put_compact_string(buf, &self.name);
310 } else {
311 put_string(buf, &self.name);
312 }
313 }
314 if version >= 0 {
315 {
316 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
317 for it in &self.partitions {
318 it.encode(buf, version)?;
319 }
320 }
321 }
322 if flex {
323 let tagged = WriteTaggedFields::new();
324 tagged.write(buf, &self.unknown_tagged_fields);
325 }
326 Ok(())
327 }
328 fn encoded_len(&self, version: i16) -> usize {
329 let flex = version >= 2;
330 let mut n: usize = 0;
331 if version >= 0 {
332 n += if flex {
333 compact_string_len(&self.name)
334 } else {
335 string_len(&self.name)
336 };
337 }
338 if version >= 0 {
339 n += {
340 let prefix =
341 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
342 let body: usize = (self.partitions)
343 .iter()
344 .map(|it| it.encoded_len(version))
345 .sum();
346 prefix + body
347 };
348 }
349 if flex {
350 let known_pairs: Vec<(u32, usize)> = Vec::new();
351 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
352 }
353 n
354 }
355}
356impl Decode<'_> for DescribeLogDirsTopic {
357 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
358 let flex = version >= 2;
359 let mut out = Self::default();
360 if version >= 0 {
361 out.name = if flex {
362 get_compact_string_owned(buf)?
363 } else {
364 get_string_owned(buf)?
365 };
366 }
367 if version >= 0 {
368 out.partitions = {
369 let n = crate::primitives::array::get_array_len(buf, flex)?;
370 let mut v = Vec::with_capacity(n);
371 for _ in 0..n {
372 v.push(DescribeLogDirsPartition::decode(buf, version)?);
373 }
374 v
375 };
376 }
377 if flex {
378 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
379 }
380 Ok(out)
381 }
382}
383#[cfg(test)]
384impl DescribeLogDirsTopic {
385 #[must_use]
386 pub fn populated(version: i16) -> Self {
387 let mut m = Self::default();
388 if version >= 0 {
389 m.name = "x".to_string();
390 }
391 if version >= 0 {
392 m.partitions = vec![DescribeLogDirsPartition::populated(version)];
393 }
394 m
395 }
396}
397#[derive(Debug, Clone, PartialEq, Eq, Default)]
398pub struct DescribeLogDirsPartition {
399 pub partition_index: i32,
400 pub partition_size: i64,
401 pub offset_lag: i64,
402 pub is_future_key: bool,
403 pub unknown_tagged_fields: UnknownTaggedFields,
404}
405impl Encode for DescribeLogDirsPartition {
406 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
407 let flex = version >= 2;
408 if version >= 0 {
409 put_i32(buf, self.partition_index);
410 }
411 if version >= 0 {
412 put_i64(buf, self.partition_size);
413 }
414 if version >= 0 {
415 put_i64(buf, self.offset_lag);
416 }
417 if version >= 0 {
418 put_bool(buf, self.is_future_key);
419 }
420 if flex {
421 let tagged = WriteTaggedFields::new();
422 tagged.write(buf, &self.unknown_tagged_fields);
423 }
424 Ok(())
425 }
426 fn encoded_len(&self, version: i16) -> usize {
427 let flex = version >= 2;
428 let mut n: usize = 0;
429 if version >= 0 {
430 n += 4;
431 }
432 if version >= 0 {
433 n += 8;
434 }
435 if version >= 0 {
436 n += 8;
437 }
438 if version >= 0 {
439 n += 1;
440 }
441 if flex {
442 let known_pairs: Vec<(u32, usize)> = Vec::new();
443 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
444 }
445 n
446 }
447}
448impl Decode<'_> for DescribeLogDirsPartition {
449 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
450 let flex = version >= 2;
451 let mut out = Self::default();
452 if version >= 0 {
453 out.partition_index = get_i32(buf)?;
454 }
455 if version >= 0 {
456 out.partition_size = get_i64(buf)?;
457 }
458 if version >= 0 {
459 out.offset_lag = get_i64(buf)?;
460 }
461 if version >= 0 {
462 out.is_future_key = get_bool(buf)?;
463 }
464 if flex {
465 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
466 }
467 Ok(out)
468 }
469}
470#[cfg(test)]
471impl DescribeLogDirsPartition {
472 #[must_use]
473 pub fn populated(version: i16) -> Self {
474 let mut m = Self::default();
475 if version >= 0 {
476 m.partition_index = 1i32;
477 }
478 if version >= 0 {
479 m.partition_size = 1i64;
480 }
481 if version >= 0 {
482 m.offset_lag = 1i64;
483 }
484 if version >= 0 {
485 m.is_future_key = true;
486 }
487 m
488 }
489}
490
491#[must_use]
494#[allow(unused_comparisons)]
495pub fn default_json(version: i16) -> ::serde_json::Value {
496 let mut obj = ::serde_json::Map::new();
497 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
498 if version >= 3 {
499 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
500 }
501 obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
502 ::serde_json::Value::Object(obj)
503}