Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeClusterResponse.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    primitives::{
7        fixed::{get_bool, get_i8, get_i16, get_i32, put_bool, put_i8, put_i16, put_i32},
8        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,
11            string_len,
12        },
13        string_bytes_borrowed::{
14            get_compact_nullable_string_borrowed, get_compact_string_borrowed,
15            get_nullable_string_borrowed, get_string_borrowed,
16        },
17    },
18    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 60;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 2;
23pub const FLEXIBLE_MIN: i16 = 0;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27    version >= FLEXIBLE_MIN
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: UnknownTaggedFields::default(),
53        }
54    }
55}
56impl<'a> DescribeClusterResponse<'a> {
57    /// # Panics
58    ///
59    /// Panics if a records field contains an invalid encoded record batch.
60    #[must_use]
61    pub fn to_owned(&self) -> crate::owned::describe_cluster_response::DescribeClusterResponse {
62        crate::owned::describe_cluster_response::DescribeClusterResponse {
63            throttle_time_ms: (self.throttle_time_ms),
64            error_code: (self.error_code),
65            error_message: (self.error_message).map(std::string::ToString::to_string),
66            endpoint_type: (self.endpoint_type),
67            cluster_id: (self.cluster_id).to_string(),
68            controller_id: (self.controller_id),
69            brokers: (self.brokers)
70                .iter()
71                .map(DescribeClusterBroker::to_owned)
72                .collect(),
73            cluster_authorized_operations: (self.cluster_authorized_operations),
74            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
75        }
76    }
77    fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
78        if version >= 0 {
79            put_i32(buf, self.throttle_time_ms);
80        }
81    }
82    fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
83        if version >= 0 {
84            put_i16(buf, self.error_code);
85        }
86    }
87    fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
88        if version >= 0 {
89            if flex {
90                let () = put_compact_nullable_string(buf, self.error_message);
91            } else {
92                let () = put_nullable_string(buf, self.error_message);
93            }
94        }
95    }
96    fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
97        if version >= 1 {
98            put_i8(buf, self.endpoint_type);
99        }
100    }
101    fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
102        if version >= 0 {
103            if flex {
104                let () = put_compact_string(buf, self.cluster_id);
105            } else {
106                let () = put_string(buf, self.cluster_id);
107            }
108        }
109    }
110    fn encode_field_5<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
111        if version >= 0 {
112            put_i32(buf, self.controller_id);
113        }
114    }
115    fn encode_field_6<B: BufMut>(
116        &self,
117        buf: &mut B,
118        version: i16,
119        flex: bool,
120    ) -> Result<(), ProtocolError> {
121        if version >= 0 {
122            {
123                crate::primitives::array::put_array_len(buf, (self.brokers).len(), flex);
124                for it in &self.brokers {
125                    it.encode(buf, version)?;
126                }
127            };
128        }
129        Ok(())
130    }
131    fn encode_field_7<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
132        if version >= 0 {
133            put_i32(buf, self.cluster_authorized_operations);
134        }
135    }
136    fn encode_tagged_fields<B: BufMut>(&self, buf: &mut B, _version: i16, flex: bool) {
137        if flex {
138            let tagged = WriteTaggedFields::new();
139            tagged.write(buf, &self.unknown_tagged_fields);
140        }
141    }
142    fn decode_field_0(
143        out: &mut Self,
144        buf: &mut &'a [u8],
145        version: i16,
146        _flex: bool,
147    ) -> Result<(), ProtocolError> {
148        if version >= 0 {
149            out.throttle_time_ms = get_i32(buf)?;
150        }
151        Ok(())
152    }
153    fn decode_field_1(
154        out: &mut Self,
155        buf: &mut &'a [u8],
156        version: i16,
157        _flex: bool,
158    ) -> Result<(), ProtocolError> {
159        if version >= 0 {
160            out.error_code = get_i16(buf)?;
161        }
162        Ok(())
163    }
164    fn decode_field_2(
165        out: &mut Self,
166        buf: &mut &'a [u8],
167        version: i16,
168        flex: bool,
169    ) -> Result<(), ProtocolError> {
170        if version >= 0 {
171            out.error_message = if flex {
172                get_compact_nullable_string_borrowed(buf)?
173            } else {
174                get_nullable_string_borrowed(buf)?
175            };
176        }
177        Ok(())
178    }
179    fn decode_field_3(
180        out: &mut Self,
181        buf: &mut &'a [u8],
182        version: i16,
183        _flex: bool,
184    ) -> Result<(), ProtocolError> {
185        if version >= 1 {
186            out.endpoint_type = get_i8(buf)?;
187        }
188        Ok(())
189    }
190    fn decode_field_4(
191        out: &mut Self,
192        buf: &mut &'a [u8],
193        version: i16,
194        flex: bool,
195    ) -> Result<(), ProtocolError> {
196        if version >= 0 {
197            out.cluster_id = if flex {
198                get_compact_string_borrowed(buf)?
199            } else {
200                get_string_borrowed(buf)?
201            };
202        }
203        Ok(())
204    }
205    fn decode_field_5(
206        out: &mut Self,
207        buf: &mut &'a [u8],
208        version: i16,
209        _flex: bool,
210    ) -> Result<(), ProtocolError> {
211        if version >= 0 {
212            out.controller_id = get_i32(buf)?;
213        }
214        Ok(())
215    }
216    fn decode_field_6(
217        out: &mut Self,
218        buf: &mut &'a [u8],
219        version: i16,
220        flex: bool,
221    ) -> Result<(), ProtocolError> {
222        if version >= 0 {
223            out.brokers = {
224                let n = crate::primitives::array::get_array_len(buf, flex)?;
225                let mut v = Vec::with_capacity(n);
226                for _ in 0..n {
227                    v.push(DescribeClusterBroker::decode_borrow(buf, version)?);
228                }
229                v
230            };
231        }
232        Ok(())
233    }
234    fn decode_field_7(
235        out: &mut Self,
236        buf: &mut &'a [u8],
237        version: i16,
238        _flex: bool,
239    ) -> Result<(), ProtocolError> {
240        if version >= 0 {
241            out.cluster_authorized_operations = get_i32(buf)?;
242        }
243        Ok(())
244    }
245    fn decode_tagged_fields(
246        out: &mut Self,
247        buf: &mut &'a [u8],
248        _version: i16,
249        flex: bool,
250    ) -> Result<(), ProtocolError> {
251        if flex {
252            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
253        }
254        Ok(())
255    }
256}
257impl Encode for DescribeClusterResponse<'_> {
258    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
259        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
260            return Err(ProtocolError::UnsupportedVersion {
261                api_key: API_KEY,
262                version,
263            });
264        }
265        let flex = is_flexible(version);
266        self.encode_field_0(buf, version, flex);
267        self.encode_field_1(buf, version, flex);
268        self.encode_field_2(buf, version, flex);
269        self.encode_field_3(buf, version, flex);
270        self.encode_field_4(buf, version, flex);
271        self.encode_field_5(buf, version, flex);
272        self.encode_field_6(buf, version, flex)?;
273        self.encode_field_7(buf, version, flex);
274        self.encode_tagged_fields(buf, version, flex);
275        Ok(())
276    }
277    fn encoded_len(&self, version: i16) -> usize {
278        let flex = is_flexible(version);
279        let mut n: usize = 0;
280        if version >= 0 {
281            n += 4;
282        }
283        if version >= 0 {
284            n += 2;
285        }
286        if version >= 0 {
287            n += if flex {
288                compact_nullable_string_len(self.error_message)
289            } else {
290                nullable_string_len(self.error_message)
291            };
292        }
293        if version >= 1 {
294            n += 1;
295        }
296        if version >= 0 {
297            n += if flex {
298                compact_string_len(self.cluster_id)
299            } else {
300                string_len(self.cluster_id)
301            };
302        }
303        if version >= 0 {
304            n += 4;
305        }
306        if version >= 0 {
307            n += {
308                let prefix =
309                    crate::primitives::array::array_len_prefix_len((self.brokers).len(), flex);
310                let body: usize = (self.brokers)
311                    .iter()
312                    .map(|it| it.encoded_len(version))
313                    .sum();
314                prefix + body
315            };
316        }
317        if version >= 0 {
318            n += 4;
319        }
320        if flex {
321            let known_pairs: Vec<(u32, usize)> = Vec::new();
322            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
323        }
324        n
325    }
326}
327impl<'de> DecodeBorrow<'de> for DescribeClusterResponse<'de> {
328    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
329        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
330            return Err(ProtocolError::UnsupportedVersion {
331                api_key: API_KEY,
332                version,
333            });
334        }
335        let flex = is_flexible(version);
336        let mut out = Self::default();
337        Self::decode_field_0(&mut out, buf, version, flex)?;
338        Self::decode_field_1(&mut out, buf, version, flex)?;
339        Self::decode_field_2(&mut out, buf, version, flex)?;
340        Self::decode_field_3(&mut out, buf, version, flex)?;
341        Self::decode_field_4(&mut out, buf, version, flex)?;
342        Self::decode_field_5(&mut out, buf, version, flex)?;
343        Self::decode_field_6(&mut out, buf, version, flex)?;
344        Self::decode_field_7(&mut out, buf, version, flex)?;
345        Self::decode_tagged_fields(&mut out, buf, version, flex)?;
346        Ok(out)
347    }
348}
349#[cfg(test)]
350impl DescribeClusterResponse<'_> {
351    #[must_use]
352    pub fn populated(version: i16) -> Self {
353        let mut m = Self::default();
354        if version >= 0 {
355            m.throttle_time_ms = 1i32;
356        }
357        if version >= 0 {
358            m.error_code = 1i16;
359        }
360        if version >= 0 {
361            m.error_message = Some("x");
362        }
363        if version >= 1 {
364            m.endpoint_type = 1i8;
365        }
366        if version >= 0 {
367            m.cluster_id = "x";
368        }
369        if version >= 0 {
370            m.controller_id = 1i32;
371        }
372        if version >= 0 {
373            m.brokers = vec![DescribeClusterBroker::populated(version)];
374        }
375        if version >= 0 {
376            m.cluster_authorized_operations = 1i32;
377        }
378        m
379    }
380}
381#[derive(Debug, Clone, PartialEq, Eq, Default)]
382pub struct DescribeClusterBroker<'a> {
383    pub broker_id: i32,
384    pub host: &'a str,
385    pub port: i32,
386    pub rack: Option<&'a str>,
387    pub is_fenced: bool,
388    pub unknown_tagged_fields: UnknownTaggedFields,
389}
390impl DescribeClusterBroker<'_> {
391    /// # Panics
392    ///
393    /// Panics if a records field contains an invalid encoded record batch.
394    #[must_use]
395    pub fn to_owned(&self) -> crate::owned::describe_cluster_response::DescribeClusterBroker {
396        crate::owned::describe_cluster_response::DescribeClusterBroker {
397            broker_id: (self.broker_id),
398            host: (self.host).to_string(),
399            port: (self.port),
400            rack: (self.rack).map(std::string::ToString::to_string),
401            is_fenced: (self.is_fenced),
402            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
403        }
404    }
405}
406impl Encode for DescribeClusterBroker<'_> {
407    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
408        let flex = version >= 0;
409        if version >= 0 {
410            put_i32(buf, self.broker_id);
411        }
412        if version >= 0 {
413            if flex {
414                let () = put_compact_string(buf, self.host);
415            } else {
416                let () = put_string(buf, self.host);
417            }
418        }
419        if version >= 0 {
420            put_i32(buf, self.port);
421        }
422        if version >= 0 {
423            if flex {
424                let () = put_compact_nullable_string(buf, self.rack);
425            } else {
426                let () = put_nullable_string(buf, self.rack);
427            }
428        }
429        if version >= 2 {
430            put_bool(buf, self.is_fenced);
431        }
432        if flex {
433            let tagged = WriteTaggedFields::new();
434            tagged.write(buf, &self.unknown_tagged_fields);
435        }
436        Ok(())
437    }
438    fn encoded_len(&self, version: i16) -> usize {
439        let flex = version >= 0;
440        let mut n: usize = 0;
441        if version >= 0 {
442            n += 4;
443        }
444        if version >= 0 {
445            n += if flex {
446                compact_string_len(self.host)
447            } else {
448                string_len(self.host)
449            };
450        }
451        if version >= 0 {
452            n += 4;
453        }
454        if version >= 0 {
455            n += if flex {
456                compact_nullable_string_len(self.rack)
457            } else {
458                nullable_string_len(self.rack)
459            };
460        }
461        if version >= 2 {
462            n += 1;
463        }
464        if flex {
465            let known_pairs: Vec<(u32, usize)> = Vec::new();
466            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
467        }
468        n
469    }
470}
471impl<'de> DecodeBorrow<'de> for DescribeClusterBroker<'de> {
472    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
473        let flex = version >= 0;
474        let mut out = Self::default();
475        if version >= 0 {
476            out.broker_id = get_i32(buf)?;
477        }
478        if version >= 0 {
479            out.host = if flex {
480                get_compact_string_borrowed(buf)?
481            } else {
482                get_string_borrowed(buf)?
483            };
484        }
485        if version >= 0 {
486            out.port = get_i32(buf)?;
487        }
488        if version >= 0 {
489            out.rack = if flex {
490                get_compact_nullable_string_borrowed(buf)?
491            } else {
492                get_nullable_string_borrowed(buf)?
493            };
494        }
495        if version >= 2 {
496            out.is_fenced = get_bool(buf)?;
497        }
498        if flex {
499            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
500        }
501        Ok(out)
502    }
503}
504#[cfg(test)]
505impl DescribeClusterBroker<'_> {
506    #[must_use]
507    pub fn populated(version: i16) -> Self {
508        let mut m = Self::default();
509        if version >= 0 {
510            m.broker_id = 1i32;
511        }
512        if version >= 0 {
513            m.host = "x";
514        }
515        if version >= 0 {
516            m.port = 1i32;
517        }
518        if version >= 0 {
519            m.rack = Some("x");
520        }
521        if version >= 2 {
522            m.is_fenced = true;
523        }
524        m
525    }
526}