Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeLogDirsResponse.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, get_i64, put_bool, put_i16, put_i32, put_i64};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned,
8    put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
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
18#[inline]
19fn is_flexible(version: i16) -> bool { 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}
28
29impl Encode for DescribeLogDirsResponse {
30    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
31        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
32            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
33        }
34        let flex = is_flexible(version);
35        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
36        if version >= 3 { put_i16(buf, self.error_code) }
37        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.results).len(), flex); for it in &self.results { it.encode(buf, version)?; } } }
38        if flex {
39            let tagged = WriteTaggedFields::new();
40            tagged.write(buf, &self.unknown_tagged_fields);
41        }
42        Ok(())
43    }
44    fn encoded_len(&self, version: i16) -> usize {
45        let flex = is_flexible(version);
46        let mut n: usize = 0;
47        if version >= 0 { n += 4; }
48        if version >= 3 { n += 2; }
49        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.results).len(), flex); let body: usize = (self.results).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
50        if flex {
51            let known_pairs: Vec<(u32, usize)> = Vec::new();
52            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
53        }
54        n
55    }
56}
57
58impl<'de> Decode<'de> for DescribeLogDirsResponse {
59    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
60        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
61            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
62        }
63        let flex = is_flexible(version);
64        let mut out = Self::default();
65        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
66        if version >= 3 { out.error_code = get_i16(buf)?; }
67        if version >= 0 { out.results = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribeLogDirsResult::decode(buf, version)?); } v }; }
68        if flex {
69            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
70                Ok(false)
71            })?;
72        }
73        Ok(out)
74    }
75}
76
77#[derive(Debug, Clone, PartialEq, Eq)]
78pub struct DescribeLogDirsResult {
79    pub error_code: i16,
80    pub log_dir: String,
81    pub topics: Vec<DescribeLogDirsTopic>,
82    pub total_bytes: i64,
83    pub usable_bytes: i64,
84    pub is_cordoned: bool,
85    pub unknown_tagged_fields: UnknownTaggedFields,
86}
87
88impl Default for DescribeLogDirsResult {
89    fn default() -> Self {
90        Self {
91            error_code: 0i16,
92            log_dir: String::new(),
93            topics: Vec::new(),
94            total_bytes: -1i64,
95            usable_bytes: -1i64,
96            is_cordoned: false,
97            unknown_tagged_fields: Default::default(),
98        }
99    }
100}
101
102impl Encode for DescribeLogDirsResult {
103    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
104        let flex = version >= 2;
105        if version >= 0 { put_i16(buf, self.error_code) }
106        if version >= 0 { if flex { put_compact_string(buf, &self.log_dir) } else { put_string(buf, &self.log_dir) } }
107        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
108        if version >= 4 { put_i64(buf, self.total_bytes) }
109        if version >= 4 { put_i64(buf, self.usable_bytes) }
110        if version >= 5 { put_bool(buf, self.is_cordoned) }
111        if flex {
112            let tagged = WriteTaggedFields::new();
113            tagged.write(buf, &self.unknown_tagged_fields);
114        }
115        Ok(())
116    }
117    fn encoded_len(&self, version: i16) -> usize {
118        let flex = version >= 2;
119        let mut n: usize = 0;
120        if version >= 0 { n += 2; }
121        if version >= 0 { n += if flex { compact_string_len(&self.log_dir) } else { string_len(&self.log_dir) }; }
122        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
123        if version >= 4 { n += 8; }
124        if version >= 4 { n += 8; }
125        if version >= 5 { n += 1; }
126        if flex {
127            let known_pairs: Vec<(u32, usize)> = Vec::new();
128            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
129        }
130        n
131    }
132}
133
134impl<'de> Decode<'de> for DescribeLogDirsResult {
135    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
136        let flex = version >= 2;
137        let mut out = Self::default();
138        if version >= 0 { out.error_code = get_i16(buf)?; }
139        if version >= 0 { out.log_dir = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
140        if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribeLogDirsTopic::decode(buf, version)?); } v }; }
141        if version >= 4 { out.total_bytes = get_i64(buf)?; }
142        if version >= 4 { out.usable_bytes = get_i64(buf)?; }
143        if version >= 5 { out.is_cordoned = get_bool(buf)?; }
144        if flex {
145            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
146                Ok(false)
147            })?;
148        }
149        Ok(out)
150    }
151}
152
153#[derive(Debug, Clone, PartialEq, Eq, Default)]
154pub struct DescribeLogDirsTopic {
155    pub name: String,
156    pub partitions: Vec<DescribeLogDirsPartition>,
157    pub unknown_tagged_fields: UnknownTaggedFields,
158}
159
160impl Encode for DescribeLogDirsTopic {
161    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
162        let flex = version >= 2;
163        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
164        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
165        if flex {
166            let tagged = WriteTaggedFields::new();
167            tagged.write(buf, &self.unknown_tagged_fields);
168        }
169        Ok(())
170    }
171    fn encoded_len(&self, version: i16) -> usize {
172        let flex = version >= 2;
173        let mut n: usize = 0;
174        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
175        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
176        if flex {
177            let known_pairs: Vec<(u32, usize)> = Vec::new();
178            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
179        }
180        n
181    }
182}
183
184impl<'de> Decode<'de> for DescribeLogDirsTopic {
185    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
186        let flex = version >= 2;
187        let mut out = Self::default();
188        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
189        if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribeLogDirsPartition::decode(buf, version)?); } v }; }
190        if flex {
191            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
192                Ok(false)
193            })?;
194        }
195        Ok(out)
196    }
197}
198
199#[derive(Debug, Clone, PartialEq, Eq, Default)]
200pub struct DescribeLogDirsPartition {
201    pub partition_index: i32,
202    pub partition_size: i64,
203    pub offset_lag: i64,
204    pub is_future_key: bool,
205    pub unknown_tagged_fields: UnknownTaggedFields,
206}
207
208impl Encode for DescribeLogDirsPartition {
209    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
210        let flex = version >= 2;
211        if version >= 0 { put_i32(buf, self.partition_index) }
212        if version >= 0 { put_i64(buf, self.partition_size) }
213        if version >= 0 { put_i64(buf, self.offset_lag) }
214        if version >= 0 { put_bool(buf, self.is_future_key) }
215        if flex {
216            let tagged = WriteTaggedFields::new();
217            tagged.write(buf, &self.unknown_tagged_fields);
218        }
219        Ok(())
220    }
221    fn encoded_len(&self, version: i16) -> usize {
222        let flex = version >= 2;
223        let mut n: usize = 0;
224        if version >= 0 { n += 4; }
225        if version >= 0 { n += 8; }
226        if version >= 0 { n += 8; }
227        if version >= 0 { n += 1; }
228        if flex {
229            let known_pairs: Vec<(u32, usize)> = Vec::new();
230            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
231        }
232        n
233    }
234}
235
236impl<'de> Decode<'de> for DescribeLogDirsPartition {
237    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
238        let flex = version >= 2;
239        let mut out = Self::default();
240        if version >= 0 { out.partition_index = get_i32(buf)?; }
241        if version >= 0 { out.partition_size = get_i64(buf)?; }
242        if version >= 0 { out.offset_lag = get_i64(buf)?; }
243        if version >= 0 { out.is_future_key = get_bool(buf)?; }
244        if flex {
245            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
246                Ok(false)
247            })?;
248        }
249        Ok(out)
250    }
251}
252
253/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
254/// Only includes fields valid for the given version.
255#[must_use]
256#[allow(unused_comparisons)]
257pub fn default_json(version: i16) -> ::serde_json::Value {
258    let mut obj = ::serde_json::Map::new();
259    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
260    if version >= 3 {
261        obj.insert("errorCode".to_string(), ::serde_json::json!(0));
262    }
263    obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
264    ::serde_json::Value::Object(obj)
265}