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