Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ShareFetchRequest.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_bool, get_i8, get_i32, get_i64, put_bool, put_i8, put_i32, put_i64},
10        string_bytes::{
11            compact_nullable_string_len, get_compact_nullable_string_owned,
12            get_nullable_string_owned, nullable_string_len, put_compact_nullable_string,
13            put_nullable_string,
14        },
15        uuid::{Uuid, get_uuid, put_uuid},
16    },
17    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 78;
20pub const MIN_VERSION: i16 = 1;
21pub const MAX_VERSION: i16 = 2;
22pub const LATEST_STABLE_VERSION: i16 = 2;
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)]
30pub struct ShareFetchRequest {
31    pub group_id: Option<String>,
32    pub member_id: Option<String>,
33    pub share_session_epoch: i32,
34    pub max_wait_ms: i32,
35    pub min_bytes: i32,
36    pub max_bytes: i32,
37    pub max_records: i32,
38    pub batch_size: i32,
39    pub share_acquire_mode: i8,
40    pub is_renew_ack: bool,
41    pub topics: Vec<FetchTopic>,
42    pub forgotten_topics_data: Vec<ForgottenTopic>,
43    pub unknown_tagged_fields: UnknownTaggedFields,
44}
45impl Default for ShareFetchRequest {
46    fn default() -> Self {
47        Self {
48            group_id: None,
49            member_id: Some(String::new()),
50            share_session_epoch: 0i32,
51            max_wait_ms: 0i32,
52            min_bytes: 0i32,
53            max_bytes: 2_147_483_647i32,
54            max_records: 0i32,
55            batch_size: 0i32,
56            share_acquire_mode: 0i8,
57            is_renew_ack: false,
58            topics: Vec::new(),
59            forgotten_topics_data: Vec::new(),
60            unknown_tagged_fields: UnknownTaggedFields::default(),
61        }
62    }
63}
64impl ShareFetchRequest {
65    fn encode_field_0<B: BufMut>(
66        &self,
67        buf: &mut B,
68        version: i16,
69        flex: bool,
70    ) -> Result<(), ProtocolError> {
71        if version >= 0 {
72            if flex {
73                put_compact_nullable_string(buf, self.group_id.as_deref())?;
74            } else {
75                put_nullable_string(buf, self.group_id.as_deref())?;
76            }
77        }
78        Ok(())
79    }
80    fn encode_field_1<B: BufMut>(
81        &self,
82        buf: &mut B,
83        version: i16,
84        flex: bool,
85    ) -> Result<(), ProtocolError> {
86        if version >= 0 {
87            if flex {
88                put_compact_nullable_string(buf, self.member_id.as_deref())?;
89            } else {
90                put_nullable_string(buf, self.member_id.as_deref())?;
91            }
92        }
93        Ok(())
94    }
95    fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
96        if version >= 0 {
97            put_i32(buf, self.share_session_epoch);
98        }
99    }
100    fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
101        if version >= 0 {
102            put_i32(buf, self.max_wait_ms);
103        }
104    }
105    fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
106        if version >= 0 {
107            put_i32(buf, self.min_bytes);
108        }
109    }
110    fn encode_field_5<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
111        if version >= 0 {
112            put_i32(buf, self.max_bytes);
113        }
114    }
115    fn encode_field_6<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
116        if version >= 1 {
117            put_i32(buf, self.max_records);
118        }
119    }
120    fn encode_field_7<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
121        if version >= 1 {
122            put_i32(buf, self.batch_size);
123        }
124    }
125    fn encode_field_8<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
126        if version >= 2 {
127            put_i8(buf, self.share_acquire_mode);
128        }
129    }
130    fn encode_field_9<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
131        if version >= 2 {
132            put_bool(buf, self.is_renew_ack);
133        }
134    }
135    fn encode_field_10<B: BufMut>(
136        &self,
137        buf: &mut B,
138        version: i16,
139        flex: bool,
140    ) -> Result<(), ProtocolError> {
141        if version >= 0 {
142            {
143                put_array_len(buf, (self.topics).len(), flex)?;
144                for it in &self.topics {
145                    it.encode(buf, version)?;
146                }
147            }
148        }
149        Ok(())
150    }
151    fn encode_field_11<B: BufMut>(
152        &self,
153        buf: &mut B,
154        version: i16,
155        flex: bool,
156    ) -> Result<(), ProtocolError> {
157        if version >= 0 {
158            {
159                put_array_len(buf, (self.forgotten_topics_data).len(), flex)?;
160                for it in &self.forgotten_topics_data {
161                    it.encode(buf, version)?;
162                }
163            }
164        }
165        Ok(())
166    }
167    fn encode_tagged_fields<B: BufMut>(
168        &self,
169        buf: &mut B,
170        _version: i16,
171        flex: bool,
172    ) -> Result<(), ProtocolError> {
173        if flex {
174            let tagged = WriteTaggedFields::new();
175            tagged.write(buf, &self.unknown_tagged_fields)?;
176        }
177        Ok(())
178    }
179    fn decode_field_0<B: Buf>(
180        out: &mut Self,
181        buf: &mut B,
182        version: i16,
183        flex: bool,
184    ) -> Result<(), ProtocolError> {
185        if version >= 0 {
186            out.group_id = if flex {
187                get_compact_nullable_string_owned(buf)?
188            } else {
189                get_nullable_string_owned(buf)?
190            };
191        }
192        Ok(())
193    }
194    fn decode_field_1<B: Buf>(
195        out: &mut Self,
196        buf: &mut B,
197        version: i16,
198        flex: bool,
199    ) -> Result<(), ProtocolError> {
200        if version >= 0 {
201            out.member_id = if flex {
202                get_compact_nullable_string_owned(buf)?
203            } else {
204                get_nullable_string_owned(buf)?
205            };
206        }
207        Ok(())
208    }
209    fn decode_field_2<B: Buf>(
210        out: &mut Self,
211        buf: &mut B,
212        version: i16,
213        _flex: bool,
214    ) -> Result<(), ProtocolError> {
215        if version >= 0 {
216            out.share_session_epoch = get_i32(buf)?;
217        }
218        Ok(())
219    }
220    fn decode_field_3<B: Buf>(
221        out: &mut Self,
222        buf: &mut B,
223        version: i16,
224        _flex: bool,
225    ) -> Result<(), ProtocolError> {
226        if version >= 0 {
227            out.max_wait_ms = get_i32(buf)?;
228        }
229        Ok(())
230    }
231    fn decode_field_4<B: Buf>(
232        out: &mut Self,
233        buf: &mut B,
234        version: i16,
235        _flex: bool,
236    ) -> Result<(), ProtocolError> {
237        if version >= 0 {
238            out.min_bytes = get_i32(buf)?;
239        }
240        Ok(())
241    }
242    fn decode_field_5<B: Buf>(
243        out: &mut Self,
244        buf: &mut B,
245        version: i16,
246        _flex: bool,
247    ) -> Result<(), ProtocolError> {
248        if version >= 0 {
249            out.max_bytes = get_i32(buf)?;
250        }
251        Ok(())
252    }
253    fn decode_field_6<B: Buf>(
254        out: &mut Self,
255        buf: &mut B,
256        version: i16,
257        _flex: bool,
258    ) -> Result<(), ProtocolError> {
259        if version >= 1 {
260            out.max_records = get_i32(buf)?;
261        }
262        Ok(())
263    }
264    fn decode_field_7<B: Buf>(
265        out: &mut Self,
266        buf: &mut B,
267        version: i16,
268        _flex: bool,
269    ) -> Result<(), ProtocolError> {
270        if version >= 1 {
271            out.batch_size = get_i32(buf)?;
272        }
273        Ok(())
274    }
275    fn decode_field_8<B: Buf>(
276        out: &mut Self,
277        buf: &mut B,
278        version: i16,
279        _flex: bool,
280    ) -> Result<(), ProtocolError> {
281        if version >= 2 {
282            out.share_acquire_mode = get_i8(buf)?;
283        }
284        Ok(())
285    }
286    fn decode_field_9<B: Buf>(
287        out: &mut Self,
288        buf: &mut B,
289        version: i16,
290        _flex: bool,
291    ) -> Result<(), ProtocolError> {
292        if version >= 2 {
293            out.is_renew_ack = get_bool(buf)?;
294        }
295        Ok(())
296    }
297    fn decode_field_10<B: Buf>(
298        out: &mut Self,
299        buf: &mut B,
300        version: i16,
301        flex: bool,
302    ) -> Result<(), ProtocolError> {
303        if version >= 0 {
304            out.topics = {
305                let n = get_array_len(buf, flex)?;
306                let mut v = Vec::with_capacity(n);
307                for _ in 0..n {
308                    v.push(FetchTopic::decode(buf, version)?);
309                }
310                v
311            };
312        }
313        Ok(())
314    }
315    fn decode_field_11<B: Buf>(
316        out: &mut Self,
317        buf: &mut B,
318        version: i16,
319        flex: bool,
320    ) -> Result<(), ProtocolError> {
321        if version >= 0 {
322            out.forgotten_topics_data = {
323                let n = get_array_len(buf, flex)?;
324                let mut v = Vec::with_capacity(n);
325                for _ in 0..n {
326                    v.push(ForgottenTopic::decode(buf, version)?);
327                }
328                v
329            };
330        }
331        Ok(())
332    }
333    fn decode_tagged_fields<B: Buf>(
334        out: &mut Self,
335        buf: &mut B,
336        _version: i16,
337        flex: bool,
338    ) -> Result<(), ProtocolError> {
339        if flex {
340            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
341        }
342        Ok(())
343    }
344}
345impl Encode for ShareFetchRequest {
346    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
347        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
348            return Err(ProtocolError::UnsupportedVersion {
349                api_key: API_KEY,
350                version,
351            });
352        }
353        let flex = is_flexible(version);
354        self.encode_field_0(buf, version, flex)?;
355        self.encode_field_1(buf, version, flex)?;
356        self.encode_field_2(buf, version, flex);
357        self.encode_field_3(buf, version, flex);
358        self.encode_field_4(buf, version, flex);
359        self.encode_field_5(buf, version, flex);
360        self.encode_field_6(buf, version, flex);
361        self.encode_field_7(buf, version, flex);
362        self.encode_field_8(buf, version, flex);
363        self.encode_field_9(buf, version, flex);
364        self.encode_field_10(buf, version, flex)?;
365        self.encode_field_11(buf, version, flex)?;
366        self.encode_tagged_fields(buf, version, flex)?;
367        Ok(())
368    }
369    fn encoded_len(&self, version: i16) -> usize {
370        let flex = is_flexible(version);
371        let mut n: usize = 0;
372        if version >= 0 {
373            n += if flex {
374                compact_nullable_string_len(self.group_id.as_deref())
375            } else {
376                nullable_string_len(self.group_id.as_deref())
377            };
378        }
379        if version >= 0 {
380            n += if flex {
381                compact_nullable_string_len(self.member_id.as_deref())
382            } else {
383                nullable_string_len(self.member_id.as_deref())
384            };
385        }
386        if version >= 0 {
387            n += 4;
388        }
389        if version >= 0 {
390            n += 4;
391        }
392        if version >= 0 {
393            n += 4;
394        }
395        if version >= 0 {
396            n += 4;
397        }
398        if version >= 1 {
399            n += 4;
400        }
401        if version >= 1 {
402            n += 4;
403        }
404        if version >= 2 {
405            n += 1;
406        }
407        if version >= 2 {
408            n += 1;
409        }
410        if version >= 0 {
411            n += {
412                let prefix = array_len_prefix_len((self.topics).len(), flex);
413                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
414                prefix + body
415            };
416        }
417        if version >= 0 {
418            n += {
419                let prefix = array_len_prefix_len((self.forgotten_topics_data).len(), flex);
420                let body: usize = (self.forgotten_topics_data)
421                    .iter()
422                    .map(|it| it.encoded_len(version))
423                    .sum();
424                prefix + body
425            };
426        }
427        if flex {
428            let known_pairs: Vec<(u32, usize)> = Vec::new();
429            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
430        }
431        n
432    }
433}
434impl Decode<'_> for ShareFetchRequest {
435    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
436        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
437            return Err(ProtocolError::UnsupportedVersion {
438                api_key: API_KEY,
439                version,
440            });
441        }
442        let flex = is_flexible(version);
443        let mut out = Self::default();
444        Self::decode_field_0(&mut out, buf, version, flex)?;
445        Self::decode_field_1(&mut out, buf, version, flex)?;
446        Self::decode_field_2(&mut out, buf, version, flex)?;
447        Self::decode_field_3(&mut out, buf, version, flex)?;
448        Self::decode_field_4(&mut out, buf, version, flex)?;
449        Self::decode_field_5(&mut out, buf, version, flex)?;
450        Self::decode_field_6(&mut out, buf, version, flex)?;
451        Self::decode_field_7(&mut out, buf, version, flex)?;
452        Self::decode_field_8(&mut out, buf, version, flex)?;
453        Self::decode_field_9(&mut out, buf, version, flex)?;
454        Self::decode_field_10(&mut out, buf, version, flex)?;
455        Self::decode_field_11(&mut out, buf, version, flex)?;
456        Self::decode_tagged_fields(&mut out, buf, version, flex)?;
457        Ok(out)
458    }
459}
460#[cfg(test)]
461impl ShareFetchRequest {
462    #[must_use]
463    pub fn populated(version: i16) -> Self {
464        let mut m = Self::default();
465        if version >= 0 {
466            m.group_id = Some("x".to_owned());
467        }
468        if version >= 0 {
469            m.member_id = Some("x".to_owned());
470        }
471        if version >= 0 {
472            m.share_session_epoch = 1i32;
473        }
474        if version >= 0 {
475            m.max_wait_ms = 1i32;
476        }
477        if version >= 0 {
478            m.min_bytes = 1i32;
479        }
480        if version >= 0 {
481            m.max_bytes = 1i32;
482        }
483        if version >= 1 {
484            m.max_records = 1i32;
485        }
486        if version >= 1 {
487            m.batch_size = 1i32;
488        }
489        if version >= 2 {
490            m.share_acquire_mode = 1i8;
491        }
492        if version >= 2 {
493            m.is_renew_ack = true;
494        }
495        if version >= 0 {
496            m.topics = vec![FetchTopic::populated(version)];
497        }
498        if version >= 0 {
499            m.forgotten_topics_data = vec![ForgottenTopic::populated(version)];
500        }
501        m
502    }
503}
504#[derive(Debug, Clone, PartialEq, Eq, Default)]
505pub struct FetchTopic {
506    pub topic_id: Uuid,
507    pub partitions: Vec<FetchPartition>,
508    pub unknown_tagged_fields: UnknownTaggedFields,
509}
510impl Encode for FetchTopic {
511    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
512        let flex = version >= 0;
513        if version >= 0 {
514            put_uuid(buf, self.topic_id);
515        }
516        if version >= 0 {
517            {
518                put_array_len(buf, (self.partitions).len(), flex)?;
519                for it in &self.partitions {
520                    it.encode(buf, version)?;
521                }
522            }
523        }
524        if flex {
525            let tagged = WriteTaggedFields::new();
526            tagged.write(buf, &self.unknown_tagged_fields)?;
527        }
528        Ok(())
529    }
530    fn encoded_len(&self, version: i16) -> usize {
531        let flex = version >= 0;
532        let mut n: usize = 0;
533        if version >= 0 {
534            n += 16;
535        }
536        if version >= 0 {
537            n += {
538                let prefix = array_len_prefix_len((self.partitions).len(), flex);
539                let body: usize = (self.partitions)
540                    .iter()
541                    .map(|it| it.encoded_len(version))
542                    .sum();
543                prefix + body
544            };
545        }
546        if flex {
547            let known_pairs: Vec<(u32, usize)> = Vec::new();
548            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
549        }
550        n
551    }
552}
553impl Decode<'_> for FetchTopic {
554    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
555        let flex = version >= 0;
556        let mut out = Self::default();
557        if version >= 0 {
558            out.topic_id = get_uuid(buf)?;
559        }
560        if version >= 0 {
561            out.partitions = {
562                let n = get_array_len(buf, flex)?;
563                let mut v = Vec::with_capacity(n);
564                for _ in 0..n {
565                    v.push(FetchPartition::decode(buf, version)?);
566                }
567                v
568            };
569        }
570        if flex {
571            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
572        }
573        Ok(out)
574    }
575}
576#[cfg(test)]
577impl FetchTopic {
578    #[must_use]
579    pub fn populated(version: i16) -> Self {
580        let mut m = Self::default();
581        if version >= 0 {
582            m.topic_id = Uuid([1u8; 16]);
583        }
584        if version >= 0 {
585            m.partitions = vec![FetchPartition::populated(version)];
586        }
587        m
588    }
589}
590#[derive(Debug, Clone, PartialEq, Eq, Default)]
591pub struct FetchPartition {
592    pub partition_index: i32,
593    pub partition_max_bytes: i32,
594    pub acknowledgement_batches: Vec<AcknowledgementBatch>,
595    pub unknown_tagged_fields: UnknownTaggedFields,
596}
597impl Encode for FetchPartition {
598    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
599        let flex = version >= 0;
600        if version >= 0 {
601            put_i32(buf, self.partition_index);
602        }
603        if version == 0 {
604            put_i32(buf, self.partition_max_bytes);
605        }
606        if version >= 0 {
607            {
608                put_array_len(buf, (self.acknowledgement_batches).len(), flex)?;
609                for it in &self.acknowledgement_batches {
610                    it.encode(buf, version)?;
611                }
612            }
613        }
614        if flex {
615            let tagged = WriteTaggedFields::new();
616            tagged.write(buf, &self.unknown_tagged_fields)?;
617        }
618        Ok(())
619    }
620    fn encoded_len(&self, version: i16) -> usize {
621        let flex = version >= 0;
622        let mut n: usize = 0;
623        if version >= 0 {
624            n += 4;
625        }
626        if version == 0 {
627            n += 4;
628        }
629        if version >= 0 {
630            n += {
631                let prefix = array_len_prefix_len((self.acknowledgement_batches).len(), flex);
632                let body: usize = (self.acknowledgement_batches)
633                    .iter()
634                    .map(|it| it.encoded_len(version))
635                    .sum();
636                prefix + body
637            };
638        }
639        if flex {
640            let known_pairs: Vec<(u32, usize)> = Vec::new();
641            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
642        }
643        n
644    }
645}
646impl Decode<'_> for FetchPartition {
647    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
648        let flex = version >= 0;
649        let mut out = Self::default();
650        if version >= 0 {
651            out.partition_index = get_i32(buf)?;
652        }
653        if version == 0 {
654            out.partition_max_bytes = get_i32(buf)?;
655        }
656        if version >= 0 {
657            out.acknowledgement_batches = {
658                let n = get_array_len(buf, flex)?;
659                let mut v = Vec::with_capacity(n);
660                for _ in 0..n {
661                    v.push(AcknowledgementBatch::decode(buf, version)?);
662                }
663                v
664            };
665        }
666        if flex {
667            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
668        }
669        Ok(out)
670    }
671}
672#[cfg(test)]
673impl FetchPartition {
674    #[must_use]
675    pub fn populated(version: i16) -> Self {
676        let mut m = Self::default();
677        if version >= 0 {
678            m.partition_index = 1i32;
679        }
680        if version == 0 {
681            m.partition_max_bytes = 1i32;
682        }
683        if version >= 0 {
684            m.acknowledgement_batches = vec![AcknowledgementBatch::populated(version)];
685        }
686        m
687    }
688}
689#[derive(Debug, Clone, PartialEq, Eq, Default)]
690pub struct AcknowledgementBatch {
691    pub first_offset: i64,
692    pub last_offset: i64,
693    pub acknowledge_types: Vec<i8>,
694    pub unknown_tagged_fields: UnknownTaggedFields,
695}
696impl Encode for AcknowledgementBatch {
697    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
698        let flex = version >= 0;
699        if version >= 0 {
700            put_i64(buf, self.first_offset);
701        }
702        if version >= 0 {
703            put_i64(buf, self.last_offset);
704        }
705        if version >= 0 {
706            {
707                put_array_len(buf, (self.acknowledge_types).len(), flex)?;
708                for it in &self.acknowledge_types {
709                    put_i8(buf, *it);
710                }
711            }
712        }
713        if flex {
714            let tagged = WriteTaggedFields::new();
715            tagged.write(buf, &self.unknown_tagged_fields)?;
716        }
717        Ok(())
718    }
719    fn encoded_len(&self, version: i16) -> usize {
720        let flex = version >= 0;
721        let mut n: usize = 0;
722        if version >= 0 {
723            n += 8;
724        }
725        if version >= 0 {
726            n += 8;
727        }
728        if version >= 0 {
729            n += {
730                let prefix = array_len_prefix_len((self.acknowledge_types).len(), flex);
731                let body: usize = (self.acknowledge_types).iter().map(|_| 1).sum();
732                prefix + body
733            };
734        }
735        if flex {
736            let known_pairs: Vec<(u32, usize)> = Vec::new();
737            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
738        }
739        n
740    }
741}
742impl Decode<'_> for AcknowledgementBatch {
743    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
744        let flex = version >= 0;
745        let mut out = Self::default();
746        if version >= 0 {
747            out.first_offset = get_i64(buf)?;
748        }
749        if version >= 0 {
750            out.last_offset = get_i64(buf)?;
751        }
752        if version >= 0 {
753            out.acknowledge_types = {
754                let n = get_array_len(buf, flex)?;
755                let mut v = Vec::with_capacity(n);
756                for _ in 0..n {
757                    v.push(get_i8(buf)?);
758                }
759                v
760            };
761        }
762        if flex {
763            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
764        }
765        Ok(out)
766    }
767}
768#[cfg(test)]
769impl AcknowledgementBatch {
770    #[must_use]
771    pub fn populated(version: i16) -> Self {
772        let mut m = Self::default();
773        if version >= 0 {
774            m.first_offset = 1i64;
775        }
776        if version >= 0 {
777            m.last_offset = 1i64;
778        }
779        if version >= 0 {
780            m.acknowledge_types = vec![1i8];
781        }
782        m
783    }
784}
785#[derive(Debug, Clone, PartialEq, Eq, Default)]
786pub struct ForgottenTopic {
787    pub topic_id: Uuid,
788    pub partitions: Vec<i32>,
789    pub unknown_tagged_fields: UnknownTaggedFields,
790}
791impl Encode for ForgottenTopic {
792    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
793        let flex = version >= 0;
794        if version >= 0 {
795            put_uuid(buf, self.topic_id);
796        }
797        if version >= 0 {
798            {
799                put_array_len(buf, (self.partitions).len(), flex)?;
800                for it in &self.partitions {
801                    put_i32(buf, *it);
802                }
803            }
804        }
805        if flex {
806            let tagged = WriteTaggedFields::new();
807            tagged.write(buf, &self.unknown_tagged_fields)?;
808        }
809        Ok(())
810    }
811    fn encoded_len(&self, version: i16) -> usize {
812        let flex = version >= 0;
813        let mut n: usize = 0;
814        if version >= 0 {
815            n += 16;
816        }
817        if version >= 0 {
818            n += {
819                let prefix = array_len_prefix_len((self.partitions).len(), flex);
820                let body: usize = (self.partitions).iter().map(|_| 4).sum();
821                prefix + body
822            };
823        }
824        if flex {
825            let known_pairs: Vec<(u32, usize)> = Vec::new();
826            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
827        }
828        n
829    }
830}
831impl Decode<'_> for ForgottenTopic {
832    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
833        let flex = version >= 0;
834        let mut out = Self::default();
835        if version >= 0 {
836            out.topic_id = get_uuid(buf)?;
837        }
838        if version >= 0 {
839            out.partitions = {
840                let n = get_array_len(buf, flex)?;
841                let mut v = Vec::with_capacity(n);
842                for _ in 0..n {
843                    v.push(get_i32(buf)?);
844                }
845                v
846            };
847        }
848        if flex {
849            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
850        }
851        Ok(out)
852    }
853}
854#[cfg(test)]
855impl ForgottenTopic {
856    #[must_use]
857    pub fn populated(version: i16) -> Self {
858        let mut m = Self::default();
859        if version >= 0 {
860            m.topic_id = Uuid([1u8; 16]);
861        }
862        if version >= 0 {
863            m.partitions = vec![1i32];
864        }
865        m
866    }
867}
868/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
869/// Only includes fields valid for the given version.
870#[must_use]
871#[allow(unused_comparisons)]
872pub fn default_json(version: i16) -> ::serde_json::Value {
873    let mut obj = ::serde_json::Map::new();
874    obj.insert("groupId".to_owned(), ::serde_json::Value::Null);
875    obj.insert(
876        "memberId".to_owned(),
877        ::serde_json::Value::String(String::new()),
878    );
879    obj.insert("shareSessionEpoch".to_owned(), ::serde_json::json!(0));
880    obj.insert("maxWaitMs".to_owned(), ::serde_json::json!(0));
881    obj.insert("minBytes".to_owned(), ::serde_json::json!(0));
882    obj.insert("maxBytes".to_owned(), ::serde_json::json!(2_147_483_647));
883    if version >= 1 {
884        obj.insert("maxRecords".to_owned(), ::serde_json::json!(0));
885    }
886    if version >= 1 {
887        obj.insert("batchSize".to_owned(), ::serde_json::json!(0));
888    }
889    if version >= 2 {
890        obj.insert("shareAcquireMode".to_owned(), ::serde_json::json!(0));
891    }
892    if version >= 2 {
893        obj.insert("isRenewAck".to_owned(), ::serde_json::Value::Bool(false));
894    }
895    obj.insert("topics".to_owned(), ::serde_json::Value::Array(vec![]));
896    obj.insert(
897        "forgottenTopicsData".to_owned(),
898        ::serde_json::Value::Array(vec![]),
899    );
900    ::serde_json::Value::Object(obj)
901}
902impl crate::ProtocolRequest for ShareFetchRequest {
903    const API_KEY: i16 = API_KEY;
904    const MIN_VERSION: i16 = MIN_VERSION;
905    const MAX_VERSION: i16 = MAX_VERSION;
906    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
907    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
908    type Response = super::share_fetch_response::ShareFetchResponse;
909}