crabka_protocol/opt/rustwide/workdir/generated/
DescribeClusterResponse.owned.rs1use crate::primitives::fixed::{
4 get_bool, get_i8, get_i16, get_i32, put_bool, put_i8, put_i16, put_i32,
5};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
10};
11use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
12use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
13use bytes::{Buf, BufMut};
14pub const API_KEY: i16 = 60;
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 2;
17pub const FLEXIBLE_MIN: i16 = 0;
18#[inline]
19fn is_flexible(version: i16) -> bool {
20 version >= FLEXIBLE_MIN
21}
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub struct DescribeClusterResponse {
24 pub throttle_time_ms: i32,
25 pub error_code: i16,
26 pub error_message: Option<String>,
27 pub endpoint_type: i8,
28 pub cluster_id: String,
29 pub controller_id: i32,
30 pub brokers: Vec<DescribeClusterBroker>,
31 pub cluster_authorized_operations: i32,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Default for DescribeClusterResponse {
35 fn default() -> Self {
36 Self {
37 throttle_time_ms: 0i32,
38 error_code: 0i16,
39 error_message: None,
40 endpoint_type: 1i8,
41 cluster_id: String::new(),
42 controller_id: -1i32,
43 brokers: Vec::new(),
44 cluster_authorized_operations: -2_147_483_648i32,
45 unknown_tagged_fields: Default::default(),
46 }
47 }
48}
49impl Encode for DescribeClusterResponse {
50 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
51 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
52 return Err(ProtocolError::UnsupportedVersion {
53 api_key: API_KEY,
54 version,
55 });
56 }
57 let flex = is_flexible(version);
58 if version >= 0 {
59 put_i32(buf, self.throttle_time_ms);
60 }
61 if version >= 0 {
62 put_i16(buf, self.error_code);
63 }
64 if version >= 0 {
65 if flex {
66 put_compact_nullable_string(buf, self.error_message.as_deref());
67 } else {
68 put_nullable_string(buf, self.error_message.as_deref());
69 }
70 }
71 if version >= 1 {
72 put_i8(buf, self.endpoint_type);
73 }
74 if version >= 0 {
75 if flex {
76 put_compact_string(buf, &self.cluster_id);
77 } else {
78 put_string(buf, &self.cluster_id);
79 }
80 }
81 if version >= 0 {
82 put_i32(buf, self.controller_id);
83 }
84 if version >= 0 {
85 {
86 crate::primitives::array::put_array_len(buf, (self.brokers).len(), flex);
87 for it in &self.brokers {
88 it.encode(buf, version)?;
89 }
90 }
91 }
92 if version >= 0 {
93 put_i32(buf, self.cluster_authorized_operations);
94 }
95 if flex {
96 let tagged = WriteTaggedFields::new();
97 tagged.write(buf, &self.unknown_tagged_fields);
98 }
99 Ok(())
100 }
101 fn encoded_len(&self, version: i16) -> usize {
102 let flex = is_flexible(version);
103 let mut n: usize = 0;
104 if version >= 0 {
105 n += 4;
106 }
107 if version >= 0 {
108 n += 2;
109 }
110 if version >= 0 {
111 n += if flex {
112 compact_nullable_string_len(self.error_message.as_deref())
113 } else {
114 nullable_string_len(self.error_message.as_deref())
115 };
116 }
117 if version >= 1 {
118 n += 1;
119 }
120 if version >= 0 {
121 n += if flex {
122 compact_string_len(&self.cluster_id)
123 } else {
124 string_len(&self.cluster_id)
125 };
126 }
127 if version >= 0 {
128 n += 4;
129 }
130 if version >= 0 {
131 n += {
132 let prefix =
133 crate::primitives::array::array_len_prefix_len((self.brokers).len(), flex);
134 let body: usize = (self.brokers)
135 .iter()
136 .map(|it| it.encoded_len(version))
137 .sum();
138 prefix + body
139 };
140 }
141 if version >= 0 {
142 n += 4;
143 }
144 if flex {
145 let known_pairs: Vec<(u32, usize)> = Vec::new();
146 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
147 }
148 n
149 }
150}
151impl Decode<'_> for DescribeClusterResponse {
152 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
153 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
154 return Err(ProtocolError::UnsupportedVersion {
155 api_key: API_KEY,
156 version,
157 });
158 }
159 let flex = is_flexible(version);
160 let mut out = Self::default();
161 if version >= 0 {
162 out.throttle_time_ms = get_i32(buf)?;
163 }
164 if version >= 0 {
165 out.error_code = get_i16(buf)?;
166 }
167 if version >= 0 {
168 out.error_message = if flex {
169 get_compact_nullable_string_owned(buf)?
170 } else {
171 get_nullable_string_owned(buf)?
172 };
173 }
174 if version >= 1 {
175 out.endpoint_type = get_i8(buf)?;
176 }
177 if version >= 0 {
178 out.cluster_id = if flex {
179 get_compact_string_owned(buf)?
180 } else {
181 get_string_owned(buf)?
182 };
183 }
184 if version >= 0 {
185 out.controller_id = get_i32(buf)?;
186 }
187 if version >= 0 {
188 out.brokers = {
189 let n = crate::primitives::array::get_array_len(buf, flex)?;
190 let mut v = Vec::with_capacity(n);
191 for _ in 0..n {
192 v.push(DescribeClusterBroker::decode(buf, version)?);
193 }
194 v
195 };
196 }
197 if version >= 0 {
198 out.cluster_authorized_operations = get_i32(buf)?;
199 }
200 if flex {
201 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
202 }
203 Ok(out)
204 }
205}
206#[cfg(test)]
207impl DescribeClusterResponse {
208 #[must_use]
209 pub fn populated(version: i16) -> Self {
210 let mut m = Self::default();
211 if version >= 0 {
212 m.throttle_time_ms = 1i32;
213 }
214 if version >= 0 {
215 m.error_code = 1i16;
216 }
217 if version >= 0 {
218 m.error_message = Some("x".to_string());
219 }
220 if version >= 1 {
221 m.endpoint_type = 1i8;
222 }
223 if version >= 0 {
224 m.cluster_id = "x".to_string();
225 }
226 if version >= 0 {
227 m.controller_id = 1i32;
228 }
229 if version >= 0 {
230 m.brokers = vec![DescribeClusterBroker::populated(version)];
231 }
232 if version >= 0 {
233 m.cluster_authorized_operations = 1i32;
234 }
235 m
236 }
237}
238#[derive(Debug, Clone, PartialEq, Eq, Default)]
239pub struct DescribeClusterBroker {
240 pub broker_id: i32,
241 pub host: String,
242 pub port: i32,
243 pub rack: Option<String>,
244 pub is_fenced: bool,
245 pub unknown_tagged_fields: UnknownTaggedFields,
246}
247impl Encode for DescribeClusterBroker {
248 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
249 let flex = version >= 0;
250 if version >= 0 {
251 put_i32(buf, self.broker_id);
252 }
253 if version >= 0 {
254 if flex {
255 put_compact_string(buf, &self.host);
256 } else {
257 put_string(buf, &self.host);
258 }
259 }
260 if version >= 0 {
261 put_i32(buf, self.port);
262 }
263 if version >= 0 {
264 if flex {
265 put_compact_nullable_string(buf, self.rack.as_deref());
266 } else {
267 put_nullable_string(buf, self.rack.as_deref());
268 }
269 }
270 if version >= 2 {
271 put_bool(buf, self.is_fenced);
272 }
273 if flex {
274 let tagged = WriteTaggedFields::new();
275 tagged.write(buf, &self.unknown_tagged_fields);
276 }
277 Ok(())
278 }
279 fn encoded_len(&self, version: i16) -> usize {
280 let flex = version >= 0;
281 let mut n: usize = 0;
282 if version >= 0 {
283 n += 4;
284 }
285 if version >= 0 {
286 n += if flex {
287 compact_string_len(&self.host)
288 } else {
289 string_len(&self.host)
290 };
291 }
292 if version >= 0 {
293 n += 4;
294 }
295 if version >= 0 {
296 n += if flex {
297 compact_nullable_string_len(self.rack.as_deref())
298 } else {
299 nullable_string_len(self.rack.as_deref())
300 };
301 }
302 if version >= 2 {
303 n += 1;
304 }
305 if flex {
306 let known_pairs: Vec<(u32, usize)> = Vec::new();
307 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
308 }
309 n
310 }
311}
312impl Decode<'_> for DescribeClusterBroker {
313 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
314 let flex = version >= 0;
315 let mut out = Self::default();
316 if version >= 0 {
317 out.broker_id = get_i32(buf)?;
318 }
319 if version >= 0 {
320 out.host = if flex {
321 get_compact_string_owned(buf)?
322 } else {
323 get_string_owned(buf)?
324 };
325 }
326 if version >= 0 {
327 out.port = get_i32(buf)?;
328 }
329 if version >= 0 {
330 out.rack = if flex {
331 get_compact_nullable_string_owned(buf)?
332 } else {
333 get_nullable_string_owned(buf)?
334 };
335 }
336 if version >= 2 {
337 out.is_fenced = get_bool(buf)?;
338 }
339 if flex {
340 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
341 }
342 Ok(out)
343 }
344}
345#[cfg(test)]
346impl DescribeClusterBroker {
347 #[must_use]
348 pub fn populated(version: i16) -> Self {
349 let mut m = Self::default();
350 if version >= 0 {
351 m.broker_id = 1i32;
352 }
353 if version >= 0 {
354 m.host = "x".to_string();
355 }
356 if version >= 0 {
357 m.port = 1i32;
358 }
359 if version >= 0 {
360 m.rack = Some("x".to_string());
361 }
362 if version >= 2 {
363 m.is_fenced = true;
364 }
365 m
366 }
367}
368#[must_use]
371#[allow(unused_comparisons)]
372pub fn default_json(version: i16) -> ::serde_json::Value {
373 let mut obj = ::serde_json::Map::new();
374 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
375 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
376 obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
377 if version >= 1 {
378 obj.insert("endpointType".to_string(), ::serde_json::json!(1));
379 }
380 obj.insert(
381 "clusterId".to_string(),
382 ::serde_json::Value::String(String::new()),
383 );
384 obj.insert("controllerId".to_string(), ::serde_json::json!(-1));
385 obj.insert("brokers".to_string(), ::serde_json::Value::Array(vec![]));
386 obj.insert(
387 "clusterAuthorizedOperations".to_string(),
388 ::serde_json::json!(-2147483648),
389 );
390 ::serde_json::Value::Object(obj)
391}