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 AlterConfigsResourceResponse {
24 pub error_code: i16,
28
29 pub error_message: Option<StrBytes>,
33
34 pub resource_type: i8,
38
39 pub resource_name: StrBytes,
43
44 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
46}
47
48impl AlterConfigsResourceResponse {
49 pub fn with_error_code(mut self, value: i16) -> Self {
55 self.error_code = value;
56 self
57 }
58 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
64 self.error_message = value;
65 self
66 }
67 pub fn with_resource_type(mut self, value: i8) -> Self {
73 self.resource_type = value;
74 self
75 }
76 pub fn with_resource_name(mut self, value: StrBytes) -> Self {
82 self.resource_name = value;
83 self
84 }
85 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
87 self.unknown_tagged_fields = value;
88 self
89 }
90 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
92 self.unknown_tagged_fields.insert(key, value);
93 self
94 }
95}
96
97#[cfg(feature = "broker")]
98impl Encodable for AlterConfigsResourceResponse {
99 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
100 if version < 0 || version > 2 {
101 bail!("specified version not supported by this message type");
102 }
103 types::Int16.encode(buf, &self.error_code)?;
104 if version >= 2 {
105 types::CompactString.encode(buf, &self.error_message)?;
106 } else {
107 types::String.encode(buf, &self.error_message)?;
108 }
109 types::Int8.encode(buf, &self.resource_type)?;
110 if version >= 2 {
111 types::CompactString.encode(buf, &self.resource_name)?;
112 } else {
113 types::String.encode(buf, &self.resource_name)?;
114 }
115 if version >= 2 {
116 let num_tagged_fields = self.unknown_tagged_fields.len();
117 if num_tagged_fields > std::u32::MAX as usize {
118 bail!(
119 "Too many tagged fields to encode ({} fields)",
120 num_tagged_fields
121 );
122 }
123 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
124
125 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
126 }
127 Ok(())
128 }
129 fn compute_size(&self, version: i16) -> Result<usize> {
130 let mut total_size = 0;
131 total_size += types::Int16.compute_size(&self.error_code)?;
132 if version >= 2 {
133 total_size += types::CompactString.compute_size(&self.error_message)?;
134 } else {
135 total_size += types::String.compute_size(&self.error_message)?;
136 }
137 total_size += types::Int8.compute_size(&self.resource_type)?;
138 if version >= 2 {
139 total_size += types::CompactString.compute_size(&self.resource_name)?;
140 } else {
141 total_size += types::String.compute_size(&self.resource_name)?;
142 }
143 if version >= 2 {
144 let num_tagged_fields = self.unknown_tagged_fields.len();
145 if num_tagged_fields > std::u32::MAX as usize {
146 bail!(
147 "Too many tagged fields to encode ({} fields)",
148 num_tagged_fields
149 );
150 }
151 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
152
153 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
154 }
155 Ok(total_size)
156 }
157}
158
159#[cfg(feature = "client")]
160impl Decodable for AlterConfigsResourceResponse {
161 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
162 if version < 0 || version > 2 {
163 bail!("specified version not supported by this message type");
164 }
165 let error_code = types::Int16.decode(buf)?;
166 let error_message = if version >= 2 {
167 types::CompactString.decode(buf)?
168 } else {
169 types::String.decode(buf)?
170 };
171 let resource_type = types::Int8.decode(buf)?;
172 let resource_name = if version >= 2 {
173 types::CompactString.decode(buf)?
174 } else {
175 types::String.decode(buf)?
176 };
177 let mut unknown_tagged_fields = BTreeMap::new();
178 if version >= 2 {
179 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
180 for _ in 0..num_tagged_fields {
181 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
182 let size: u32 = types::UnsignedVarInt.decode(buf)?;
183 let unknown_value = buf.try_get_bytes(size as usize)?;
184 unknown_tagged_fields.insert(tag as i32, unknown_value);
185 }
186 }
187 Ok(Self {
188 error_code,
189 error_message,
190 resource_type,
191 resource_name,
192 unknown_tagged_fields,
193 })
194 }
195}
196
197impl Default for AlterConfigsResourceResponse {
198 fn default() -> Self {
199 Self {
200 error_code: 0,
201 error_message: Some(Default::default()),
202 resource_type: 0,
203 resource_name: Default::default(),
204 unknown_tagged_fields: BTreeMap::new(),
205 }
206 }
207}
208
209impl Message for AlterConfigsResourceResponse {
210 const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
211 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
212}
213
214#[non_exhaustive]
216#[derive(Debug, Clone, PartialEq)]
217pub struct AlterConfigsResponse {
218 pub throttle_time_ms: i32,
222
223 pub responses: Vec<AlterConfigsResourceResponse>,
227
228 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
230}
231
232impl AlterConfigsResponse {
233 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
239 self.throttle_time_ms = value;
240 self
241 }
242 pub fn with_responses(mut self, value: Vec<AlterConfigsResourceResponse>) -> Self {
248 self.responses = value;
249 self
250 }
251 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
253 self.unknown_tagged_fields = value;
254 self
255 }
256 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
258 self.unknown_tagged_fields.insert(key, value);
259 self
260 }
261}
262
263#[cfg(feature = "broker")]
264impl Encodable for AlterConfigsResponse {
265 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
266 if version < 0 || version > 2 {
267 bail!("specified version not supported by this message type");
268 }
269 types::Int32.encode(buf, &self.throttle_time_ms)?;
270 if version >= 2 {
271 types::CompactArray(types::Struct { version }).encode(buf, &self.responses)?;
272 } else {
273 types::Array(types::Struct { version }).encode(buf, &self.responses)?;
274 }
275 if version >= 2 {
276 let num_tagged_fields = self.unknown_tagged_fields.len();
277 if num_tagged_fields > std::u32::MAX as usize {
278 bail!(
279 "Too many tagged fields to encode ({} fields)",
280 num_tagged_fields
281 );
282 }
283 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
284
285 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
286 }
287 Ok(())
288 }
289 fn compute_size(&self, version: i16) -> Result<usize> {
290 let mut total_size = 0;
291 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
292 if version >= 2 {
293 total_size +=
294 types::CompactArray(types::Struct { version }).compute_size(&self.responses)?;
295 } else {
296 total_size += types::Array(types::Struct { version }).compute_size(&self.responses)?;
297 }
298 if version >= 2 {
299 let num_tagged_fields = self.unknown_tagged_fields.len();
300 if num_tagged_fields > std::u32::MAX as usize {
301 bail!(
302 "Too many tagged fields to encode ({} fields)",
303 num_tagged_fields
304 );
305 }
306 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
307
308 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
309 }
310 Ok(total_size)
311 }
312}
313
314#[cfg(feature = "client")]
315impl Decodable for AlterConfigsResponse {
316 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
317 if version < 0 || version > 2 {
318 bail!("specified version not supported by this message type");
319 }
320 let throttle_time_ms = types::Int32.decode(buf)?;
321 let responses = if version >= 2 {
322 types::CompactArray(types::Struct { version }).decode(buf)?
323 } else {
324 types::Array(types::Struct { version }).decode(buf)?
325 };
326 let mut unknown_tagged_fields = BTreeMap::new();
327 if version >= 2 {
328 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
329 for _ in 0..num_tagged_fields {
330 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
331 let size: u32 = types::UnsignedVarInt.decode(buf)?;
332 let unknown_value = buf.try_get_bytes(size as usize)?;
333 unknown_tagged_fields.insert(tag as i32, unknown_value);
334 }
335 }
336 Ok(Self {
337 throttle_time_ms,
338 responses,
339 unknown_tagged_fields,
340 })
341 }
342}
343
344impl Default for AlterConfigsResponse {
345 fn default() -> Self {
346 Self {
347 throttle_time_ms: 0,
348 responses: Default::default(),
349 unknown_tagged_fields: BTreeMap::new(),
350 }
351 }
352}
353
354impl Message for AlterConfigsResponse {
355 const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
356 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
357}
358
359impl HeaderVersion for AlterConfigsResponse {
360 fn header_version(version: i16) -> i16 {
361 if version >= 2 {
362 1
363 } else {
364 0
365 }
366 }
367}