Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeClusterRequest.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::fixed::{get_bool, get_i8, put_bool, put_i8},
7    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
8};
9pub const API_KEY: i16 = 60;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 2;
12pub const LATEST_STABLE_VERSION: i16 = 2;
13pub const FLEXIBLE_MIN: i16 = 0;
14#[inline]
15#[must_use]
16pub fn is_flexible(version: i16) -> bool {
17    version >= FLEXIBLE_MIN
18}
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct DescribeClusterRequest {
21    pub include_cluster_authorized_operations: bool,
22    pub endpoint_type: i8,
23    pub include_fenced_brokers: bool,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Default for DescribeClusterRequest {
27    fn default() -> Self {
28        Self {
29            include_cluster_authorized_operations: false,
30            endpoint_type: 1i8,
31            include_fenced_brokers: false,
32            unknown_tagged_fields: UnknownTaggedFields::default(),
33        }
34    }
35}
36impl DescribeClusterRequest {
37    /// # Panics
38    ///
39    /// Panics if a records field contains an invalid encoded record batch.
40    #[must_use]
41    pub fn to_owned(&self) -> crate::owned::describe_cluster_request::DescribeClusterRequest {
42        crate::owned::describe_cluster_request::DescribeClusterRequest {
43            include_cluster_authorized_operations: (self.include_cluster_authorized_operations),
44            endpoint_type: (self.endpoint_type),
45            include_fenced_brokers: (self.include_fenced_brokers),
46            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
47        }
48    }
49}
50impl Encode for DescribeClusterRequest {
51    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
52        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
53            return Err(ProtocolError::UnsupportedVersion {
54                api_key: API_KEY,
55                version,
56            });
57        }
58        let flex = is_flexible(version);
59        if version >= 0 {
60            put_bool(buf, self.include_cluster_authorized_operations);
61        }
62        if version >= 1 {
63            put_i8(buf, self.endpoint_type);
64        }
65        if version >= 2 {
66            put_bool(buf, self.include_fenced_brokers);
67        }
68        if flex {
69            let tagged = WriteTaggedFields::new();
70            tagged.write(buf, &self.unknown_tagged_fields);
71        }
72        Ok(())
73    }
74    fn encoded_len(&self, version: i16) -> usize {
75        let flex = is_flexible(version);
76        let mut n: usize = 0;
77        if version >= 0 {
78            n += 1;
79        }
80        if version >= 1 {
81            n += 1;
82        }
83        if version >= 2 {
84            n += 1;
85        }
86        if flex {
87            let known_pairs: Vec<(u32, usize)> = Vec::new();
88            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
89        }
90        n
91    }
92}
93impl<'de> DecodeBorrow<'de> for DescribeClusterRequest {
94    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
95        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
96            return Err(ProtocolError::UnsupportedVersion {
97                api_key: API_KEY,
98                version,
99            });
100        }
101        let flex = is_flexible(version);
102        let mut out = Self::default();
103        if version >= 0 {
104            out.include_cluster_authorized_operations = get_bool(buf)?;
105        }
106        if version >= 1 {
107            out.endpoint_type = get_i8(buf)?;
108        }
109        if version >= 2 {
110            out.include_fenced_brokers = get_bool(buf)?;
111        }
112        if flex {
113            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
114        }
115        Ok(out)
116    }
117}
118#[cfg(test)]
119impl DescribeClusterRequest {
120    #[must_use]
121    pub fn populated(version: i16) -> Self {
122        let mut m = Self::default();
123        if version >= 0 {
124            m.include_cluster_authorized_operations = true;
125        }
126        if version >= 1 {
127            m.endpoint_type = 1i8;
128        }
129        if version >= 2 {
130            m.include_fenced_brokers = true;
131        }
132        m
133    }
134}