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