Skip to main content

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

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