Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeClusterRequest.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::fixed::{get_bool, get_i8, put_bool, put_i8},
8    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
9};
10pub const API_KEY: i16 = 60;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 2;
13pub const LATEST_STABLE_VERSION: i16 = 2;
14pub const FLEXIBLE_MIN: i16 = 0;
15#[inline]
16#[must_use]
17pub fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct DescribeClusterRequest {
22    pub include_cluster_authorized_operations: bool,
23    pub endpoint_type: i8,
24    pub include_fenced_brokers: bool,
25    pub unknown_tagged_fields: UnknownTaggedFields,
26}
27impl Default for DescribeClusterRequest {
28    fn default() -> Self {
29        Self {
30            include_cluster_authorized_operations: false,
31            endpoint_type: 1i8,
32            include_fenced_brokers: false,
33            unknown_tagged_fields: UnknownTaggedFields::default(),
34        }
35    }
36}
37impl Encode for DescribeClusterRequest {
38    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
39        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
40            return Err(ProtocolError::UnsupportedVersion {
41                api_key: API_KEY,
42                version,
43            });
44        }
45        let flex = is_flexible(version);
46        if version >= 0 {
47            put_bool(buf, self.include_cluster_authorized_operations);
48        }
49        if version >= 1 {
50            put_i8(buf, self.endpoint_type);
51        }
52        if version >= 2 {
53            put_bool(buf, self.include_fenced_brokers);
54        }
55        if flex {
56            let tagged = WriteTaggedFields::new();
57            tagged.write(buf, &self.unknown_tagged_fields);
58        }
59        Ok(())
60    }
61    fn encoded_len(&self, version: i16) -> usize {
62        let flex = is_flexible(version);
63        let mut n: usize = 0;
64        if version >= 0 {
65            n += 1;
66        }
67        if version >= 1 {
68            n += 1;
69        }
70        if version >= 2 {
71            n += 1;
72        }
73        if flex {
74            let known_pairs: Vec<(u32, usize)> = Vec::new();
75            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
76        }
77        n
78    }
79}
80impl Decode<'_> for DescribeClusterRequest {
81    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
82        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83            return Err(ProtocolError::UnsupportedVersion {
84                api_key: API_KEY,
85                version,
86            });
87        }
88        let flex = is_flexible(version);
89        let mut out = Self::default();
90        if version >= 0 {
91            out.include_cluster_authorized_operations = get_bool(buf)?;
92        }
93        if version >= 1 {
94            out.endpoint_type = get_i8(buf)?;
95        }
96        if version >= 2 {
97            out.include_fenced_brokers = get_bool(buf)?;
98        }
99        if flex {
100            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
101        }
102        Ok(out)
103    }
104}
105#[cfg(test)]
106impl DescribeClusterRequest {
107    #[must_use]
108    pub fn populated(version: i16) -> Self {
109        let mut m = Self::default();
110        if version >= 0 {
111            m.include_cluster_authorized_operations = true;
112        }
113        if version >= 1 {
114            m.endpoint_type = 1i8;
115        }
116        if version >= 2 {
117            m.include_fenced_brokers = true;
118        }
119        m
120    }
121}
122/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
123/// Only includes fields valid for the given version.
124#[must_use]
125#[allow(unused_comparisons)]
126pub fn default_json(version: i16) -> ::serde_json::Value {
127    let mut obj = ::serde_json::Map::new();
128    obj.insert(
129        "includeClusterAuthorizedOperations".to_string(),
130        ::serde_json::Value::Bool(false),
131    );
132    if version >= 1 {
133        obj.insert("endpointType".to_string(), ::serde_json::json!(1));
134    }
135    if version >= 2 {
136        obj.insert(
137            "includeFencedBrokers".to_string(),
138            ::serde_json::Value::Bool(false),
139        );
140    }
141    ::serde_json::Value::Object(obj)
142}
143impl crate::ProtocolRequest for DescribeClusterRequest {
144    const API_KEY: i16 = API_KEY;
145    const MIN_VERSION: i16 = MIN_VERSION;
146    const MAX_VERSION: i16 = MAX_VERSION;
147    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
148    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
149    type Response = super::describe_cluster_response::DescribeClusterResponse;
150}