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 AlterShareGroupOffsetsResponse {
24 pub throttle_time_ms: i32,
28
29 pub error_code: i16,
33
34 pub error_message: Option<StrBytes>,
38
39 pub responses: Vec<AlterShareGroupOffsetsResponseTopic>,
43
44 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
46}
47
48impl AlterShareGroupOffsetsResponse {
49 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
55 self.throttle_time_ms = value;
56 self
57 }
58 pub fn with_error_code(mut self, value: i16) -> Self {
64 self.error_code = value;
65 self
66 }
67 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
73 self.error_message = value;
74 self
75 }
76 pub fn with_responses(mut self, value: Vec<AlterShareGroupOffsetsResponseTopic>) -> Self {
82 self.responses = 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 AlterShareGroupOffsetsResponse {
99 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
100 if version != 0 {
101 bail!("specified version not supported by this message type");
102 }
103 types::Int32.encode(buf, &self.throttle_time_ms)?;
104 types::Int16.encode(buf, &self.error_code)?;
105 types::CompactString.encode(buf, &self.error_message)?;
106 types::CompactArray(types::Struct { version }).encode(buf, &self.responses)?;
107 let num_tagged_fields = self.unknown_tagged_fields.len();
108 if num_tagged_fields > std::u32::MAX as usize {
109 bail!(
110 "Too many tagged fields to encode ({} fields)",
111 num_tagged_fields
112 );
113 }
114 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
115
116 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
117 Ok(())
118 }
119 fn compute_size(&self, version: i16) -> Result<usize> {
120 let mut total_size = 0;
121 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
122 total_size += types::Int16.compute_size(&self.error_code)?;
123 total_size += types::CompactString.compute_size(&self.error_message)?;
124 total_size +=
125 types::CompactArray(types::Struct { version }).compute_size(&self.responses)?;
126 let num_tagged_fields = self.unknown_tagged_fields.len();
127 if num_tagged_fields > std::u32::MAX as usize {
128 bail!(
129 "Too many tagged fields to encode ({} fields)",
130 num_tagged_fields
131 );
132 }
133 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
134
135 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
136 Ok(total_size)
137 }
138}
139
140#[cfg(feature = "client")]
141impl Decodable for AlterShareGroupOffsetsResponse {
142 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
143 if version != 0 {
144 bail!("specified version not supported by this message type");
145 }
146 let throttle_time_ms = types::Int32.decode(buf)?;
147 let error_code = types::Int16.decode(buf)?;
148 let error_message = types::CompactString.decode(buf)?;
149 let responses = types::CompactArray(types::Struct { version }).decode(buf)?;
150 let mut unknown_tagged_fields = BTreeMap::new();
151 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
152 for _ in 0..num_tagged_fields {
153 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
154 let size: u32 = types::UnsignedVarInt.decode(buf)?;
155 let unknown_value = buf.try_get_bytes(size as usize)?;
156 unknown_tagged_fields.insert(tag as i32, unknown_value);
157 }
158 Ok(Self {
159 throttle_time_ms,
160 error_code,
161 error_message,
162 responses,
163 unknown_tagged_fields,
164 })
165 }
166}
167
168impl Default for AlterShareGroupOffsetsResponse {
169 fn default() -> Self {
170 Self {
171 throttle_time_ms: 0,
172 error_code: 0,
173 error_message: None,
174 responses: Default::default(),
175 unknown_tagged_fields: BTreeMap::new(),
176 }
177 }
178}
179
180impl Message for AlterShareGroupOffsetsResponse {
181 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
182 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
183}
184
185#[non_exhaustive]
187#[derive(Debug, Clone, PartialEq)]
188pub struct AlterShareGroupOffsetsResponsePartition {
189 pub partition_index: i32,
193
194 pub error_code: i16,
198
199 pub error_message: Option<StrBytes>,
203
204 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
206}
207
208impl AlterShareGroupOffsetsResponsePartition {
209 pub fn with_partition_index(mut self, value: i32) -> Self {
215 self.partition_index = value;
216 self
217 }
218 pub fn with_error_code(mut self, value: i16) -> Self {
224 self.error_code = value;
225 self
226 }
227 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
233 self.error_message = value;
234 self
235 }
236 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
238 self.unknown_tagged_fields = value;
239 self
240 }
241 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
243 self.unknown_tagged_fields.insert(key, value);
244 self
245 }
246}
247
248#[cfg(feature = "broker")]
249impl Encodable for AlterShareGroupOffsetsResponsePartition {
250 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
251 if version != 0 {
252 bail!("specified version not supported by this message type");
253 }
254 types::Int32.encode(buf, &self.partition_index)?;
255 types::Int16.encode(buf, &self.error_code)?;
256 types::CompactString.encode(buf, &self.error_message)?;
257 let num_tagged_fields = self.unknown_tagged_fields.len();
258 if num_tagged_fields > std::u32::MAX as usize {
259 bail!(
260 "Too many tagged fields to encode ({} fields)",
261 num_tagged_fields
262 );
263 }
264 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
265
266 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
267 Ok(())
268 }
269 fn compute_size(&self, version: i16) -> Result<usize> {
270 let mut total_size = 0;
271 total_size += types::Int32.compute_size(&self.partition_index)?;
272 total_size += types::Int16.compute_size(&self.error_code)?;
273 total_size += types::CompactString.compute_size(&self.error_message)?;
274 let num_tagged_fields = self.unknown_tagged_fields.len();
275 if num_tagged_fields > std::u32::MAX as usize {
276 bail!(
277 "Too many tagged fields to encode ({} fields)",
278 num_tagged_fields
279 );
280 }
281 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
282
283 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
284 Ok(total_size)
285 }
286}
287
288#[cfg(feature = "client")]
289impl Decodable for AlterShareGroupOffsetsResponsePartition {
290 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
291 if version != 0 {
292 bail!("specified version not supported by this message type");
293 }
294 let partition_index = types::Int32.decode(buf)?;
295 let error_code = types::Int16.decode(buf)?;
296 let error_message = types::CompactString.decode(buf)?;
297 let mut unknown_tagged_fields = BTreeMap::new();
298 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
299 for _ in 0..num_tagged_fields {
300 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
301 let size: u32 = types::UnsignedVarInt.decode(buf)?;
302 let unknown_value = buf.try_get_bytes(size as usize)?;
303 unknown_tagged_fields.insert(tag as i32, unknown_value);
304 }
305 Ok(Self {
306 partition_index,
307 error_code,
308 error_message,
309 unknown_tagged_fields,
310 })
311 }
312}
313
314impl Default for AlterShareGroupOffsetsResponsePartition {
315 fn default() -> Self {
316 Self {
317 partition_index: 0,
318 error_code: 0,
319 error_message: None,
320 unknown_tagged_fields: BTreeMap::new(),
321 }
322 }
323}
324
325impl Message for AlterShareGroupOffsetsResponsePartition {
326 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
327 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
328}
329
330#[non_exhaustive]
332#[derive(Debug, Clone, PartialEq)]
333pub struct AlterShareGroupOffsetsResponseTopic {
334 pub topic_name: super::TopicName,
338
339 pub topic_id: Uuid,
343
344 pub partitions: Vec<AlterShareGroupOffsetsResponsePartition>,
348
349 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
351}
352
353impl AlterShareGroupOffsetsResponseTopic {
354 pub fn with_topic_name(mut self, value: super::TopicName) -> Self {
360 self.topic_name = value;
361 self
362 }
363 pub fn with_topic_id(mut self, value: Uuid) -> Self {
369 self.topic_id = value;
370 self
371 }
372 pub fn with_partitions(mut self, value: Vec<AlterShareGroupOffsetsResponsePartition>) -> Self {
378 self.partitions = value;
379 self
380 }
381 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
383 self.unknown_tagged_fields = value;
384 self
385 }
386 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
388 self.unknown_tagged_fields.insert(key, value);
389 self
390 }
391}
392
393#[cfg(feature = "broker")]
394impl Encodable for AlterShareGroupOffsetsResponseTopic {
395 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
396 if version != 0 {
397 bail!("specified version not supported by this message type");
398 }
399 types::CompactString.encode(buf, &self.topic_name)?;
400 types::Uuid.encode(buf, &self.topic_id)?;
401 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
402 let num_tagged_fields = self.unknown_tagged_fields.len();
403 if num_tagged_fields > std::u32::MAX as usize {
404 bail!(
405 "Too many tagged fields to encode ({} fields)",
406 num_tagged_fields
407 );
408 }
409 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
410
411 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
412 Ok(())
413 }
414 fn compute_size(&self, version: i16) -> Result<usize> {
415 let mut total_size = 0;
416 total_size += types::CompactString.compute_size(&self.topic_name)?;
417 total_size += types::Uuid.compute_size(&self.topic_id)?;
418 total_size +=
419 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
420 let num_tagged_fields = self.unknown_tagged_fields.len();
421 if num_tagged_fields > std::u32::MAX as usize {
422 bail!(
423 "Too many tagged fields to encode ({} fields)",
424 num_tagged_fields
425 );
426 }
427 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
428
429 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
430 Ok(total_size)
431 }
432}
433
434#[cfg(feature = "client")]
435impl Decodable for AlterShareGroupOffsetsResponseTopic {
436 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
437 if version != 0 {
438 bail!("specified version not supported by this message type");
439 }
440 let topic_name = types::CompactString.decode(buf)?;
441 let topic_id = types::Uuid.decode(buf)?;
442 let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
443 let mut unknown_tagged_fields = BTreeMap::new();
444 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
445 for _ in 0..num_tagged_fields {
446 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
447 let size: u32 = types::UnsignedVarInt.decode(buf)?;
448 let unknown_value = buf.try_get_bytes(size as usize)?;
449 unknown_tagged_fields.insert(tag as i32, unknown_value);
450 }
451 Ok(Self {
452 topic_name,
453 topic_id,
454 partitions,
455 unknown_tagged_fields,
456 })
457 }
458}
459
460impl Default for AlterShareGroupOffsetsResponseTopic {
461 fn default() -> Self {
462 Self {
463 topic_name: Default::default(),
464 topic_id: Uuid::nil(),
465 partitions: Default::default(),
466 unknown_tagged_fields: BTreeMap::new(),
467 }
468 }
469}
470
471impl Message for AlterShareGroupOffsetsResponseTopic {
472 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
473 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
474}
475
476impl HeaderVersion for AlterShareGroupOffsetsResponse {
477 fn header_version(version: i16) -> i16 {
478 1
479 }
480}