1#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15 buf::{ByteBuf, ByteBufMut},
16 compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17 Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct UpdatableFeatureResult {
24 pub feature: StrBytes,
28
29 pub error_code: i16,
33
34 pub error_message: Option<StrBytes>,
38
39 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl UpdatableFeatureResult {
44 pub fn with_feature(mut self, value: StrBytes) -> Self {
50 self.feature = value;
51 self
52 }
53 pub fn with_error_code(mut self, value: i16) -> Self {
59 self.error_code = value;
60 self
61 }
62 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
68 self.error_message = value;
69 self
70 }
71 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73 self.unknown_tagged_fields = value;
74 self
75 }
76 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
78 self.unknown_tagged_fields.insert(key, value);
79 self
80 }
81}
82
83#[cfg(feature = "broker")]
84impl Encodable for UpdatableFeatureResult {
85 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86 types::CompactString.encode(buf, &self.feature)?;
87 types::Int16.encode(buf, &self.error_code)?;
88 types::CompactString.encode(buf, &self.error_message)?;
89 let num_tagged_fields = self.unknown_tagged_fields.len();
90 if num_tagged_fields > std::u32::MAX as usize {
91 bail!(
92 "Too many tagged fields to encode ({} fields)",
93 num_tagged_fields
94 );
95 }
96 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
97
98 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
99 Ok(())
100 }
101 fn compute_size(&self, version: i16) -> Result<usize> {
102 let mut total_size = 0;
103 total_size += types::CompactString.compute_size(&self.feature)?;
104 total_size += types::Int16.compute_size(&self.error_code)?;
105 total_size += types::CompactString.compute_size(&self.error_message)?;
106 let num_tagged_fields = self.unknown_tagged_fields.len();
107 if num_tagged_fields > std::u32::MAX as usize {
108 bail!(
109 "Too many tagged fields to encode ({} fields)",
110 num_tagged_fields
111 );
112 }
113 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
114
115 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
116 Ok(total_size)
117 }
118}
119
120#[cfg(feature = "client")]
121impl Decodable for UpdatableFeatureResult {
122 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
123 let feature = types::CompactString.decode(buf)?;
124 let error_code = types::Int16.decode(buf)?;
125 let error_message = types::CompactString.decode(buf)?;
126 let mut unknown_tagged_fields = BTreeMap::new();
127 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
128 for _ in 0..num_tagged_fields {
129 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
130 let size: u32 = types::UnsignedVarInt.decode(buf)?;
131 let unknown_value = buf.try_get_bytes(size as usize)?;
132 unknown_tagged_fields.insert(tag as i32, unknown_value);
133 }
134 Ok(Self {
135 feature,
136 error_code,
137 error_message,
138 unknown_tagged_fields,
139 })
140 }
141}
142
143impl Default for UpdatableFeatureResult {
144 fn default() -> Self {
145 Self {
146 feature: Default::default(),
147 error_code: 0,
148 error_message: Some(Default::default()),
149 unknown_tagged_fields: BTreeMap::new(),
150 }
151 }
152}
153
154impl Message for UpdatableFeatureResult {
155 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
156 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
157}
158
159#[non_exhaustive]
161#[derive(Debug, Clone, PartialEq)]
162pub struct UpdateFeaturesResponse {
163 pub throttle_time_ms: i32,
167
168 pub error_code: i16,
172
173 pub error_message: Option<StrBytes>,
177
178 pub results: Vec<UpdatableFeatureResult>,
182
183 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
185}
186
187impl UpdateFeaturesResponse {
188 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
194 self.throttle_time_ms = value;
195 self
196 }
197 pub fn with_error_code(mut self, value: i16) -> Self {
203 self.error_code = value;
204 self
205 }
206 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
212 self.error_message = value;
213 self
214 }
215 pub fn with_results(mut self, value: Vec<UpdatableFeatureResult>) -> Self {
221 self.results = value;
222 self
223 }
224 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
226 self.unknown_tagged_fields = value;
227 self
228 }
229 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
231 self.unknown_tagged_fields.insert(key, value);
232 self
233 }
234}
235
236#[cfg(feature = "broker")]
237impl Encodable for UpdateFeaturesResponse {
238 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
239 types::Int32.encode(buf, &self.throttle_time_ms)?;
240 types::Int16.encode(buf, &self.error_code)?;
241 types::CompactString.encode(buf, &self.error_message)?;
242 types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
243 let num_tagged_fields = self.unknown_tagged_fields.len();
244 if num_tagged_fields > std::u32::MAX as usize {
245 bail!(
246 "Too many tagged fields to encode ({} fields)",
247 num_tagged_fields
248 );
249 }
250 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
251
252 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
253 Ok(())
254 }
255 fn compute_size(&self, version: i16) -> Result<usize> {
256 let mut total_size = 0;
257 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
258 total_size += types::Int16.compute_size(&self.error_code)?;
259 total_size += types::CompactString.compute_size(&self.error_message)?;
260 total_size += types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
261 let num_tagged_fields = self.unknown_tagged_fields.len();
262 if num_tagged_fields > std::u32::MAX as usize {
263 bail!(
264 "Too many tagged fields to encode ({} fields)",
265 num_tagged_fields
266 );
267 }
268 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
269
270 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
271 Ok(total_size)
272 }
273}
274
275#[cfg(feature = "client")]
276impl Decodable for UpdateFeaturesResponse {
277 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
278 let throttle_time_ms = types::Int32.decode(buf)?;
279 let error_code = types::Int16.decode(buf)?;
280 let error_message = types::CompactString.decode(buf)?;
281 let results = types::CompactArray(types::Struct { version }).decode(buf)?;
282 let mut unknown_tagged_fields = BTreeMap::new();
283 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
284 for _ in 0..num_tagged_fields {
285 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
286 let size: u32 = types::UnsignedVarInt.decode(buf)?;
287 let unknown_value = buf.try_get_bytes(size as usize)?;
288 unknown_tagged_fields.insert(tag as i32, unknown_value);
289 }
290 Ok(Self {
291 throttle_time_ms,
292 error_code,
293 error_message,
294 results,
295 unknown_tagged_fields,
296 })
297 }
298}
299
300impl Default for UpdateFeaturesResponse {
301 fn default() -> Self {
302 Self {
303 throttle_time_ms: 0,
304 error_code: 0,
305 error_message: Some(Default::default()),
306 results: Default::default(),
307 unknown_tagged_fields: BTreeMap::new(),
308 }
309 }
310}
311
312impl Message for UpdateFeaturesResponse {
313 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
314 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
315}
316
317impl HeaderVersion for UpdateFeaturesResponse {
318 fn header_version(version: i16) -> i16 {
319 1
320 }
321}