crabka_protocol/opt/rustwide/workdir/generated/
DescribeClusterResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, get_i8, put_bool, put_i16, put_i32, put_i8};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10 string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 60;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 2;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct DescribeClusterResponse {
25 pub throttle_time_ms: i32,
26 pub error_code: i16,
27 pub error_message: Option<String>,
28 pub endpoint_type: i8,
29 pub cluster_id: String,
30 pub controller_id: i32,
31 pub brokers: Vec<DescribeClusterBroker>,
32 pub cluster_authorized_operations: i32,
33 pub unknown_tagged_fields: UnknownTaggedFields,
34}
35
36impl Default for DescribeClusterResponse {
37 fn default() -> Self {
38 Self {
39 throttle_time_ms: 0i32,
40 error_code: 0i16,
41 error_message: None,
42 endpoint_type: 1i8,
43 cluster_id: String::new(),
44 controller_id: -1i32,
45 brokers: Vec::new(),
46 cluster_authorized_operations: -2_147_483_648i32,
47 unknown_tagged_fields: Default::default(),
48 }
49 }
50}
51
52impl Encode for DescribeClusterResponse {
53 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
54 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
55 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
56 }
57 let flex = is_flexible(version);
58 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
59 if version >= 0 { put_i16(buf, self.error_code) }
60 if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
61 if version >= 1 { put_i8(buf, self.endpoint_type) }
62 if version >= 0 { if flex { put_compact_string(buf, &self.cluster_id) } else { put_string(buf, &self.cluster_id) } }
63 if version >= 0 { put_i32(buf, self.controller_id) }
64 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.brokers).len(), flex); for it in &self.brokers { it.encode(buf, version)?; } } }
65 if version >= 0 { put_i32(buf, self.cluster_authorized_operations) }
66 if flex {
67 let tagged = WriteTaggedFields::new();
68 tagged.write(buf, &self.unknown_tagged_fields);
69 }
70 Ok(())
71 }
72 fn encoded_len(&self, version: i16) -> usize {
73 let flex = is_flexible(version);
74 let mut n: usize = 0;
75 if version >= 0 { n += 4; }
76 if version >= 0 { n += 2; }
77 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
78 if version >= 1 { n += 1; }
79 if version >= 0 { n += if flex { compact_string_len(&self.cluster_id) } else { string_len(&self.cluster_id) }; }
80 if version >= 0 { n += 4; }
81 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.brokers).len(), flex); let body: usize = (self.brokers).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
82 if version >= 0 { n += 4; }
83 if flex {
84 let known_pairs: Vec<(u32, usize)> = Vec::new();
85 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
86 }
87 n
88 }
89}
90
91impl<'de> Decode<'de> for DescribeClusterResponse {
92 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
93 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
94 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
95 }
96 let flex = is_flexible(version);
97 let mut out = Self::default();
98 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
99 if version >= 0 { out.error_code = get_i16(buf)?; }
100 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
101 if version >= 1 { out.endpoint_type = get_i8(buf)?; }
102 if version >= 0 { out.cluster_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
103 if version >= 0 { out.controller_id = get_i32(buf)?; }
104 if version >= 0 { out.brokers = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribeClusterBroker::decode(buf, version)?); } v }; }
105 if version >= 0 { out.cluster_authorized_operations = get_i32(buf)?; }
106 if flex {
107 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
108 Ok(false)
109 })?;
110 }
111 Ok(out)
112 }
113}
114
115#[derive(Debug, Clone, PartialEq, Eq, Default)]
116pub struct DescribeClusterBroker {
117 pub broker_id: i32,
118 pub host: String,
119 pub port: i32,
120 pub rack: Option<String>,
121 pub is_fenced: bool,
122 pub unknown_tagged_fields: UnknownTaggedFields,
123}
124
125impl Encode for DescribeClusterBroker {
126 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
127 let flex = version >= 0;
128 if version >= 0 { put_i32(buf, self.broker_id) }
129 if version >= 0 { if flex { put_compact_string(buf, &self.host) } else { put_string(buf, &self.host) } }
130 if version >= 0 { put_i32(buf, self.port) }
131 if version >= 0 { if flex { put_compact_nullable_string(buf, self.rack.as_deref()) } else { put_nullable_string(buf, self.rack.as_deref()) } }
132 if version >= 2 { put_bool(buf, self.is_fenced) }
133 if flex {
134 let tagged = WriteTaggedFields::new();
135 tagged.write(buf, &self.unknown_tagged_fields);
136 }
137 Ok(())
138 }
139 fn encoded_len(&self, version: i16) -> usize {
140 let flex = version >= 0;
141 let mut n: usize = 0;
142 if version >= 0 { n += 4; }
143 if version >= 0 { n += if flex { compact_string_len(&self.host) } else { string_len(&self.host) }; }
144 if version >= 0 { n += 4; }
145 if version >= 0 { n += if flex { compact_nullable_string_len(self.rack.as_deref()) } else { nullable_string_len(self.rack.as_deref()) }; }
146 if version >= 2 { n += 1; }
147 if flex {
148 let known_pairs: Vec<(u32, usize)> = Vec::new();
149 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
150 }
151 n
152 }
153}
154
155impl<'de> Decode<'de> for DescribeClusterBroker {
156 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
157 let flex = version >= 0;
158 let mut out = Self::default();
159 if version >= 0 { out.broker_id = get_i32(buf)?; }
160 if version >= 0 { out.host = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
161 if version >= 0 { out.port = get_i32(buf)?; }
162 if version >= 0 { out.rack = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
163 if version >= 2 { out.is_fenced = get_bool(buf)?; }
164 if flex {
165 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
166 Ok(false)
167 })?;
168 }
169 Ok(out)
170 }
171}
172
173#[must_use]
176#[allow(unused_comparisons)]
177pub fn default_json(version: i16) -> ::serde_json::Value {
178 let mut obj = ::serde_json::Map::new();
179 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
180 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
181 obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
182 if version >= 1 {
183 obj.insert("endpointType".to_string(), ::serde_json::json!(1));
184 }
185 obj.insert("clusterId".to_string(), ::serde_json::Value::String(String::new()));
186 obj.insert("controllerId".to_string(), ::serde_json::json!(-1));
187 obj.insert("brokers".to_string(), ::serde_json::Value::Array(vec![]));
188 obj.insert("clusterAuthorizedOperations".to_string(), ::serde_json::json!(-2147483648));
189 ::serde_json::Value::Object(obj)
190}