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