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