crabka_protocol/opt/rustwide/workdir/generated/
DescribeClusterRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i8, put_bool, put_i8};
6use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
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 {
16 version >= FLEXIBLE_MIN
17}
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: Default::default(),
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 {
40 api_key: API_KEY,
41 version,
42 });
43 }
44 let flex = is_flexible(version);
45 if version >= 0 {
46 put_bool(buf, self.include_cluster_authorized_operations);
47 }
48 if version >= 1 {
49 put_i8(buf, self.endpoint_type);
50 }
51 if version >= 2 {
52 put_bool(buf, self.include_fenced_brokers);
53 }
54 if flex {
55 let tagged = WriteTaggedFields::new();
56 tagged.write(buf, &self.unknown_tagged_fields);
57 }
58 Ok(())
59 }
60 fn encoded_len(&self, version: i16) -> usize {
61 let flex = is_flexible(version);
62 let mut n: usize = 0;
63 if version >= 0 {
64 n += 1;
65 }
66 if version >= 1 {
67 n += 1;
68 }
69 if version >= 2 {
70 n += 1;
71 }
72 if flex {
73 let known_pairs: Vec<(u32, usize)> = Vec::new();
74 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
75 }
76 n
77 }
78}
79impl Decode<'_> for DescribeClusterRequest {
80 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
81 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
82 return Err(ProtocolError::UnsupportedVersion {
83 api_key: API_KEY,
84 version,
85 });
86 }
87 let flex = is_flexible(version);
88 let mut out = Self::default();
89 if version >= 0 {
90 out.include_cluster_authorized_operations = get_bool(buf)?;
91 }
92 if version >= 1 {
93 out.endpoint_type = get_i8(buf)?;
94 }
95 if version >= 2 {
96 out.include_fenced_brokers = get_bool(buf)?;
97 }
98 if flex {
99 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
100 }
101 Ok(out)
102 }
103}
104#[cfg(test)]
105impl DescribeClusterRequest {
106 #[must_use]
107 pub fn populated(version: i16) -> Self {
108 let mut m = Self::default();
109 if version >= 0 {
110 m.include_cluster_authorized_operations = true;
111 }
112 if version >= 1 {
113 m.endpoint_type = 1i8;
114 }
115 if version >= 2 {
116 m.include_fenced_brokers = true;
117 }
118 m
119 }
120}
121
122#[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}
143
144impl crate::ProtocolRequest for DescribeClusterRequest {
145 const API_KEY: i16 = API_KEY;
146 const MIN_VERSION: i16 = MIN_VERSION;
147 const MAX_VERSION: i16 = MAX_VERSION;
148 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
149 type Response = super::describe_cluster_response::DescribeClusterResponse;
150}