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