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