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