1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, nullable_string_len,
8 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
9};
10use crate::primitives::string_bytes_borrowed::{
11 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
12 get_nullable_string_borrowed, get_string_borrowed,
13};
14use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
15use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
16
17pub const API_KEY: i16 = 90;
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 1;
20pub const FLEXIBLE_MIN: i16 = 0;
21
22#[inline]
23fn is_flexible(version: i16) -> bool {
24 version >= FLEXIBLE_MIN
25}
26
27#[derive(Debug, Clone, PartialEq, Eq, Default)]
28pub struct DescribeShareGroupOffsetsResponse<'a> {
29 pub throttle_time_ms: i32,
30 pub groups: Vec<DescribeShareGroupOffsetsResponseGroup<'a>>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl DescribeShareGroupOffsetsResponse<'_> {
34 pub fn to_owned(
35 &self,
36 ) -> crate::owned::describe_share_group_offsets_response::DescribeShareGroupOffsetsResponse
37 {
38 crate::owned::describe_share_group_offsets_response::DescribeShareGroupOffsetsResponse {
39 throttle_time_ms: (self.throttle_time_ms),
40 groups: (self.groups)
41 .iter()
42 .map(DescribeShareGroupOffsetsResponseGroup::to_owned)
43 .collect(),
44 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
45 }
46 }
47}
48impl Encode for DescribeShareGroupOffsetsResponse<'_> {
49 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
50 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
51 return Err(ProtocolError::UnsupportedVersion {
52 api_key: API_KEY,
53 version,
54 });
55 }
56 let flex = is_flexible(version);
57 if version >= 0 {
58 put_i32(buf, self.throttle_time_ms);
59 }
60 if version >= 0 {
61 {
62 crate::primitives::array::put_array_len(buf, (self.groups).len(), flex);
63 for it in &self.groups {
64 it.encode(buf, version)?;
65 }
66 }
67 }
68 if flex {
69 let tagged = WriteTaggedFields::new();
70 tagged.write(buf, &self.unknown_tagged_fields);
71 }
72 Ok(())
73 }
74 fn encoded_len(&self, version: i16) -> usize {
75 let flex = is_flexible(version);
76 let mut n: usize = 0;
77 if version >= 0 {
78 n += 4;
79 }
80 if version >= 0 {
81 n += {
82 let prefix =
83 crate::primitives::array::array_len_prefix_len((self.groups).len(), flex);
84 let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum();
85 prefix + body
86 };
87 }
88 if flex {
89 let known_pairs: Vec<(u32, usize)> = Vec::new();
90 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
91 }
92 n
93 }
94}
95impl<'de> DecodeBorrow<'de> for DescribeShareGroupOffsetsResponse<'de> {
96 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
97 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
98 return Err(ProtocolError::UnsupportedVersion {
99 api_key: API_KEY,
100 version,
101 });
102 }
103 let flex = is_flexible(version);
104 let mut out = Self::default();
105 if version >= 0 {
106 out.throttle_time_ms = get_i32(buf)?;
107 }
108 if version >= 0 {
109 out.groups = {
110 let n = crate::primitives::array::get_array_len(buf, flex)?;
111 let mut v = Vec::with_capacity(n);
112 for _ in 0..n {
113 v.push(DescribeShareGroupOffsetsResponseGroup::decode_borrow(
114 buf, version,
115 )?);
116 }
117 v
118 };
119 }
120 if flex {
121 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
122 }
123 Ok(out)
124 }
125}
126#[cfg(test)]
127impl DescribeShareGroupOffsetsResponse<'_> {
128 #[must_use]
129 pub fn populated(version: i16) -> Self {
130 let mut m = Self::default();
131 if version >= 0 {
132 m.throttle_time_ms = 1i32;
133 }
134 if version >= 0 {
135 m.groups = vec![DescribeShareGroupOffsetsResponseGroup::populated(version)];
136 }
137 m
138 }
139}
140#[derive(Debug, Clone, PartialEq, Eq, Default)]
141pub struct DescribeShareGroupOffsetsResponseGroup<'a> {
142 pub group_id: &'a str,
143 pub topics: Vec<DescribeShareGroupOffsetsResponseTopic<'a>>,
144 pub error_code: i16,
145 pub error_message: Option<&'a str>,
146 pub unknown_tagged_fields: UnknownTaggedFields,
147}
148impl DescribeShareGroupOffsetsResponseGroup<'_> {
149 pub fn to_owned(
150 &self,
151 ) -> crate::owned::describe_share_group_offsets_response::DescribeShareGroupOffsetsResponseGroup
152 {
153 crate :: owned :: describe_share_group_offsets_response :: DescribeShareGroupOffsetsResponseGroup { group_id : (self . group_id) . to_string () , topics : (self . topics) . iter () . map (DescribeShareGroupOffsetsResponseTopic::to_owned) . collect () , error_code : (self . error_code) , error_message : (self . error_message) . map (std::string::ToString::to_string) , unknown_tagged_fields : self . unknown_tagged_fields . clone () , }
154 }
155}
156impl Encode for DescribeShareGroupOffsetsResponseGroup<'_> {
157 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
158 let flex = version >= 0;
159 if version >= 0 {
160 if flex {
161 put_compact_string(buf, self.group_id);
162 } else {
163 put_string(buf, self.group_id);
164 }
165 }
166 if version >= 0 {
167 {
168 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
169 for it in &self.topics {
170 it.encode(buf, version)?;
171 }
172 }
173 }
174 if version >= 0 {
175 put_i16(buf, self.error_code);
176 }
177 if version >= 0 {
178 if flex {
179 put_compact_nullable_string(buf, self.error_message);
180 } else {
181 put_nullable_string(buf, self.error_message);
182 }
183 }
184 if flex {
185 let tagged = WriteTaggedFields::new();
186 tagged.write(buf, &self.unknown_tagged_fields);
187 }
188 Ok(())
189 }
190 fn encoded_len(&self, version: i16) -> usize {
191 let flex = version >= 0;
192 let mut n: usize = 0;
193 if version >= 0 {
194 n += if flex {
195 compact_string_len(self.group_id)
196 } else {
197 string_len(self.group_id)
198 };
199 }
200 if version >= 0 {
201 n += {
202 let prefix =
203 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
204 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
205 prefix + body
206 };
207 }
208 if version >= 0 {
209 n += 2;
210 }
211 if version >= 0 {
212 n += if flex {
213 compact_nullable_string_len(self.error_message)
214 } else {
215 nullable_string_len(self.error_message)
216 };
217 }
218 if flex {
219 let known_pairs: Vec<(u32, usize)> = Vec::new();
220 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
221 }
222 n
223 }
224}
225impl<'de> DecodeBorrow<'de> for DescribeShareGroupOffsetsResponseGroup<'de> {
226 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
227 let flex = version >= 0;
228 let mut out = Self::default();
229 if version >= 0 {
230 out.group_id = if flex {
231 get_compact_string_borrowed(buf)?
232 } else {
233 get_string_borrowed(buf)?
234 };
235 }
236 if version >= 0 {
237 out.topics = {
238 let n = crate::primitives::array::get_array_len(buf, flex)?;
239 let mut v = Vec::with_capacity(n);
240 for _ in 0..n {
241 v.push(DescribeShareGroupOffsetsResponseTopic::decode_borrow(
242 buf, version,
243 )?);
244 }
245 v
246 };
247 }
248 if version >= 0 {
249 out.error_code = get_i16(buf)?;
250 }
251 if version >= 0 {
252 out.error_message = if flex {
253 get_compact_nullable_string_borrowed(buf)?
254 } else {
255 get_nullable_string_borrowed(buf)?
256 };
257 }
258 if flex {
259 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
260 }
261 Ok(out)
262 }
263}
264#[cfg(test)]
265impl DescribeShareGroupOffsetsResponseGroup<'_> {
266 #[must_use]
267 pub fn populated(version: i16) -> Self {
268 let mut m = Self::default();
269 if version >= 0 {
270 m.group_id = "x";
271 }
272 if version >= 0 {
273 m.topics = vec![DescribeShareGroupOffsetsResponseTopic::populated(version)];
274 }
275 if version >= 0 {
276 m.error_code = 1i16;
277 }
278 if version >= 0 {
279 m.error_message = Some("x");
280 }
281 m
282 }
283}
284#[derive(Debug, Clone, PartialEq, Eq, Default)]
285pub struct DescribeShareGroupOffsetsResponseTopic<'a> {
286 pub topic_name: &'a str,
287 pub topic_id: crate::primitives::uuid::Uuid,
288 pub partitions: Vec<DescribeShareGroupOffsetsResponsePartition<'a>>,
289 pub unknown_tagged_fields: UnknownTaggedFields,
290}
291impl DescribeShareGroupOffsetsResponseTopic<'_> {
292 pub fn to_owned(
293 &self,
294 ) -> crate::owned::describe_share_group_offsets_response::DescribeShareGroupOffsetsResponseTopic
295 {
296 crate :: owned :: describe_share_group_offsets_response :: DescribeShareGroupOffsetsResponseTopic { topic_name : (self . topic_name) . to_string () , topic_id : (self . topic_id) , partitions : (self . partitions) . iter () . map (DescribeShareGroupOffsetsResponsePartition::to_owned) . collect () , unknown_tagged_fields : self . unknown_tagged_fields . clone () , }
297 }
298}
299impl Encode for DescribeShareGroupOffsetsResponseTopic<'_> {
300 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
301 let flex = version >= 0;
302 if version >= 0 {
303 if flex {
304 put_compact_string(buf, self.topic_name);
305 } else {
306 put_string(buf, self.topic_name);
307 }
308 }
309 if version >= 0 {
310 crate::primitives::uuid::put_uuid(buf, self.topic_id);
311 }
312 if version >= 0 {
313 {
314 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
315 for it in &self.partitions {
316 it.encode(buf, version)?;
317 }
318 }
319 }
320 if flex {
321 let tagged = WriteTaggedFields::new();
322 tagged.write(buf, &self.unknown_tagged_fields);
323 }
324 Ok(())
325 }
326 fn encoded_len(&self, version: i16) -> usize {
327 let flex = version >= 0;
328 let mut n: usize = 0;
329 if version >= 0 {
330 n += if flex {
331 compact_string_len(self.topic_name)
332 } else {
333 string_len(self.topic_name)
334 };
335 }
336 if version >= 0 {
337 n += 16;
338 }
339 if version >= 0 {
340 n += {
341 let prefix =
342 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
343 let body: usize = (self.partitions)
344 .iter()
345 .map(|it| it.encoded_len(version))
346 .sum();
347 prefix + body
348 };
349 }
350 if flex {
351 let known_pairs: Vec<(u32, usize)> = Vec::new();
352 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
353 }
354 n
355 }
356}
357impl<'de> DecodeBorrow<'de> for DescribeShareGroupOffsetsResponseTopic<'de> {
358 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
359 let flex = version >= 0;
360 let mut out = Self::default();
361 if version >= 0 {
362 out.topic_name = if flex {
363 get_compact_string_borrowed(buf)?
364 } else {
365 get_string_borrowed(buf)?
366 };
367 }
368 if version >= 0 {
369 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
370 }
371 if version >= 0 {
372 out.partitions = {
373 let n = crate::primitives::array::get_array_len(buf, flex)?;
374 let mut v = Vec::with_capacity(n);
375 for _ in 0..n {
376 v.push(DescribeShareGroupOffsetsResponsePartition::decode_borrow(
377 buf, version,
378 )?);
379 }
380 v
381 };
382 }
383 if flex {
384 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
385 }
386 Ok(out)
387 }
388}
389#[cfg(test)]
390impl DescribeShareGroupOffsetsResponseTopic<'_> {
391 #[must_use]
392 pub fn populated(version: i16) -> Self {
393 let mut m = Self::default();
394 if version >= 0 {
395 m.topic_name = "x";
396 }
397 if version >= 0 {
398 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
399 }
400 if version >= 0 {
401 m.partitions = vec![DescribeShareGroupOffsetsResponsePartition::populated(
402 version,
403 )];
404 }
405 m
406 }
407}
408#[derive(Debug, Clone, PartialEq, Eq)]
409pub struct DescribeShareGroupOffsetsResponsePartition<'a> {
410 pub partition_index: i32,
411 pub start_offset: i64,
412 pub leader_epoch: i32,
413 pub lag: i64,
414 pub error_code: i16,
415 pub error_message: Option<&'a str>,
416 pub unknown_tagged_fields: UnknownTaggedFields,
417}
418impl Default for DescribeShareGroupOffsetsResponsePartition<'_> {
419 fn default() -> Self {
420 Self {
421 partition_index: 0i32,
422 start_offset: 0i64,
423 leader_epoch: 0i32,
424 lag: -1i64,
425 error_code: 0i16,
426 error_message: None,
427 unknown_tagged_fields: Default::default(),
428 }
429 }
430}
431impl DescribeShareGroupOffsetsResponsePartition<'_> {
432 pub fn to_owned (& self) -> crate :: owned :: describe_share_group_offsets_response :: DescribeShareGroupOffsetsResponsePartition{
433 crate :: owned :: describe_share_group_offsets_response :: DescribeShareGroupOffsetsResponsePartition { partition_index : (self . partition_index) , start_offset : (self . start_offset) , leader_epoch : (self . leader_epoch) , lag : (self . lag) , error_code : (self . error_code) , error_message : (self . error_message) . map (std::string::ToString::to_string) , unknown_tagged_fields : self . unknown_tagged_fields . clone () , }
434 }
435}
436impl Encode for DescribeShareGroupOffsetsResponsePartition<'_> {
437 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
438 let flex = version >= 0;
439 if version >= 0 {
440 put_i32(buf, self.partition_index);
441 }
442 if version >= 0 {
443 put_i64(buf, self.start_offset);
444 }
445 if version >= 0 {
446 put_i32(buf, self.leader_epoch);
447 }
448 if version >= 1 {
449 put_i64(buf, self.lag);
450 }
451 if version >= 0 {
452 put_i16(buf, self.error_code);
453 }
454 if version >= 0 {
455 if flex {
456 put_compact_nullable_string(buf, self.error_message);
457 } else {
458 put_nullable_string(buf, self.error_message);
459 }
460 }
461 if flex {
462 let tagged = WriteTaggedFields::new();
463 tagged.write(buf, &self.unknown_tagged_fields);
464 }
465 Ok(())
466 }
467 fn encoded_len(&self, version: i16) -> usize {
468 let flex = version >= 0;
469 let mut n: usize = 0;
470 if version >= 0 {
471 n += 4;
472 }
473 if version >= 0 {
474 n += 8;
475 }
476 if version >= 0 {
477 n += 4;
478 }
479 if version >= 1 {
480 n += 8;
481 }
482 if version >= 0 {
483 n += 2;
484 }
485 if version >= 0 {
486 n += if flex {
487 compact_nullable_string_len(self.error_message)
488 } else {
489 nullable_string_len(self.error_message)
490 };
491 }
492 if flex {
493 let known_pairs: Vec<(u32, usize)> = Vec::new();
494 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
495 }
496 n
497 }
498}
499impl<'de> DecodeBorrow<'de> for DescribeShareGroupOffsetsResponsePartition<'de> {
500 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
501 let flex = version >= 0;
502 let mut out = Self::default();
503 if version >= 0 {
504 out.partition_index = get_i32(buf)?;
505 }
506 if version >= 0 {
507 out.start_offset = get_i64(buf)?;
508 }
509 if version >= 0 {
510 out.leader_epoch = get_i32(buf)?;
511 }
512 if version >= 1 {
513 out.lag = get_i64(buf)?;
514 }
515 if version >= 0 {
516 out.error_code = get_i16(buf)?;
517 }
518 if version >= 0 {
519 out.error_message = if flex {
520 get_compact_nullable_string_borrowed(buf)?
521 } else {
522 get_nullable_string_borrowed(buf)?
523 };
524 }
525 if flex {
526 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
527 }
528 Ok(out)
529 }
530}
531#[cfg(test)]
532impl DescribeShareGroupOffsetsResponsePartition<'_> {
533 #[must_use]
534 pub fn populated(version: i16) -> Self {
535 let mut m = Self::default();
536 if version >= 0 {
537 m.partition_index = 1i32;
538 }
539 if version >= 0 {
540 m.start_offset = 1i64;
541 }
542 if version >= 0 {
543 m.leader_epoch = 1i32;
544 }
545 if version >= 1 {
546 m.lag = 1i64;
547 }
548 if version >= 0 {
549 m.error_code = 1i16;
550 }
551 if version >= 0 {
552 m.error_message = Some("x");
553 }
554 m
555 }
556}