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