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