Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeClusterRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i8, put_bool, put_i8};
6use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
7use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 60;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 2;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct DescribeClusterRequest {
19    pub include_cluster_authorized_operations: bool,
20    pub endpoint_type: i8,
21    pub include_fenced_brokers: bool,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Default for DescribeClusterRequest {
26    fn default() -> Self {
27        Self {
28            include_cluster_authorized_operations: false,
29            endpoint_type: 1i8,
30            include_fenced_brokers: false,
31            unknown_tagged_fields: Default::default(),
32        }
33    }
34}
35
36impl Encode for DescribeClusterRequest {
37    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
38        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
39            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
40        }
41        let flex = is_flexible(version);
42        if version >= 0 { put_bool(buf, self.include_cluster_authorized_operations) }
43        if version >= 1 { put_i8(buf, self.endpoint_type) }
44        if version >= 2 { put_bool(buf, self.include_fenced_brokers) }
45        if flex {
46            let tagged = WriteTaggedFields::new();
47            tagged.write(buf, &self.unknown_tagged_fields);
48        }
49        Ok(())
50    }
51    fn encoded_len(&self, version: i16) -> usize {
52        let flex = is_flexible(version);
53        let mut n: usize = 0;
54        if version >= 0 { n += 1; }
55        if version >= 1 { n += 1; }
56        if version >= 2 { n += 1; }
57        if flex {
58            let known_pairs: Vec<(u32, usize)> = Vec::new();
59            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
60        }
61        n
62    }
63}
64
65impl<'de> Decode<'de> for DescribeClusterRequest {
66    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
67        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
68            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
69        }
70        let flex = is_flexible(version);
71        let mut out = Self::default();
72        if version >= 0 { out.include_cluster_authorized_operations = get_bool(buf)?; }
73        if version >= 1 { out.endpoint_type = get_i8(buf)?; }
74        if version >= 2 { out.include_fenced_brokers = get_bool(buf)?; }
75        if flex {
76            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
77                Ok(false)
78            })?;
79        }
80        Ok(out)
81    }
82}
83
84/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
85/// Only includes fields valid for the given version.
86#[must_use]
87#[allow(unused_comparisons)]
88pub fn default_json(version: i16) -> ::serde_json::Value {
89    let mut obj = ::serde_json::Map::new();
90    obj.insert("includeClusterAuthorizedOperations".to_string(), ::serde_json::Value::Bool(false));
91    if version >= 1 {
92        obj.insert("endpointType".to_string(), ::serde_json::json!(1));
93    }
94    if version >= 2 {
95        obj.insert("includeFencedBrokers".to_string(), ::serde_json::Value::Bool(false));
96    }
97    ::serde_json::Value::Object(obj)
98}
99
100impl crate::ProtocolRequest for DescribeClusterRequest {
101    const API_KEY: i16 = API_KEY;
102    const MIN_VERSION: i16 = MIN_VERSION;
103    const MAX_VERSION: i16 = MAX_VERSION;
104    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
105    type Response = super::describe_cluster_response::DescribeClusterResponse;
106}