Skip to main content

kacrab_protocol/generated/
share_fetch_request.rs

1//! Generated from ShareFetchRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct ShareFetchRequestData {
17    /// The group identifier.
18    pub group_id: Option<KafkaString>,
19    /// The member ID.
20    pub member_id: Option<KafkaString>,
21    /// The current share session epoch: 0 to open a share session; -1 to close it; otherwise
22    /// increments for consecutive requests.
23    pub share_session_epoch: i32,
24    /// The maximum time in milliseconds to wait for the response.
25    pub max_wait_ms: i32,
26    /// The minimum bytes to accumulate in the response.
27    pub min_bytes: i32,
28    /// The maximum bytes to fetch. See KIP-74 for cases where this limit may not be honored.
29    pub max_bytes: i32,
30    /// The maximum number of records to fetch. This limit can be exceeded for alignment of batch
31    /// boundaries.
32    pub max_records: i32,
33    /// The optimal number of records for batches of acquired records and acknowledgements.
34    pub batch_size: i32,
35    /// The acquire mode to control the fetch behavior - 0:batch-optimized,1:record-limit.
36    pub share_acquire_mode: i8,
37    /// Whether Renew type acknowledgements present in AcknowledgementBatches.
38    pub is_renew_ack: bool,
39    /// The topics to fetch.
40    pub topics: Vec<FetchTopic>,
41    /// The partitions to remove from this share session.
42    pub forgotten_topics_data: Vec<ForgottenTopic>,
43    pub _unknown_tagged_fields: Vec<RawTaggedField>,
44}
45impl Default for ShareFetchRequestData {
46    fn default() -> Self {
47        Self {
48            group_id: None,
49            member_id: None,
50            share_session_epoch: 0_i32,
51            max_wait_ms: 0_i32,
52            min_bytes: 0_i32,
53            max_bytes: i32::MAX,
54            max_records: 0_i32,
55            batch_size: 0_i32,
56            share_acquire_mode: 0i8,
57            is_renew_ack: false,
58            topics: Vec::new(),
59            forgotten_topics_data: Vec::new(),
60            _unknown_tagged_fields: Vec::new(),
61        }
62    }
63}
64impl ShareFetchRequestData {
65    pub fn with_group_id(mut self, value: Option<KafkaString>) -> Self {
66        self.group_id = value;
67        self
68    }
69    pub fn with_member_id(mut self, value: Option<KafkaString>) -> Self {
70        self.member_id = value;
71        self
72    }
73    pub fn with_share_session_epoch(mut self, value: i32) -> Self {
74        self.share_session_epoch = value;
75        self
76    }
77    pub fn with_max_wait_ms(mut self, value: i32) -> Self {
78        self.max_wait_ms = value;
79        self
80    }
81    pub fn with_min_bytes(mut self, value: i32) -> Self {
82        self.min_bytes = value;
83        self
84    }
85    pub fn with_max_bytes(mut self, value: i32) -> Self {
86        self.max_bytes = value;
87        self
88    }
89    pub fn with_max_records(mut self, value: i32) -> Self {
90        self.max_records = value;
91        self
92    }
93    pub fn with_batch_size(mut self, value: i32) -> Self {
94        self.batch_size = value;
95        self
96    }
97    pub fn with_share_acquire_mode(mut self, value: i8) -> Self {
98        self.share_acquire_mode = value;
99        self
100    }
101    pub fn with_is_renew_ack(mut self, value: bool) -> Self {
102        self.is_renew_ack = value;
103        self
104    }
105    pub fn with_topics(mut self, value: Vec<FetchTopic>) -> Self {
106        self.topics = value;
107        self
108    }
109    pub fn with_forgotten_topics_data(mut self, value: Vec<ForgottenTopic>) -> Self {
110        self.forgotten_topics_data = value;
111        self
112    }
113    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
114        if version < 1 || version > 2 {
115            return Err(UnsupportedVersion::new(78, version).into());
116        }
117        let group_id;
118        let member_id;
119        let share_session_epoch;
120        let max_wait_ms;
121        let min_bytes;
122        let max_bytes;
123        let max_records;
124        let batch_size;
125        let mut share_acquire_mode = 0i8;
126        let mut is_renew_ack = false;
127        let topics;
128        let forgotten_topics_data;
129        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
130        group_id = read_compact_nullable_string(buf)?;
131        member_id = read_compact_nullable_string(buf)?;
132        share_session_epoch = read_i32(buf)?;
133        max_wait_ms = read_i32(buf)?;
134        min_bytes = read_i32(buf)?;
135        max_bytes = read_i32(buf)?;
136        max_records = read_i32(buf)?;
137        batch_size = read_i32(buf)?;
138        if version >= 2 {
139            share_acquire_mode = read_i8(buf)?;
140        }
141        if version >= 2 {
142            is_renew_ack = read_bool(buf)?;
143        }
144        topics = {
145            let len = read_compact_array_length(buf)?;
146            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
147            for _ in 0..len {
148                arr.push(FetchTopic::read(buf, version)?);
149            }
150            arr
151        };
152        forgotten_topics_data = {
153            let len = read_compact_array_length(buf)?;
154            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
155            for _ in 0..len {
156                arr.push(ForgottenTopic::read(buf, version)?);
157            }
158            arr
159        };
160        let tagged_fields = read_tagged_fields(buf)?;
161        for field in &tagged_fields {
162            match field.tag {
163                _ => {
164                    _unknown_tagged_fields.push(field.clone());
165                },
166            }
167        }
168        Ok(Self {
169            group_id,
170            member_id,
171            share_session_epoch,
172            max_wait_ms,
173            min_bytes,
174            max_bytes,
175            max_records,
176            batch_size,
177            share_acquire_mode,
178            is_renew_ack,
179            topics,
180            forgotten_topics_data,
181            _unknown_tagged_fields,
182        })
183    }
184    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
185        if version < 1 || version > 2 {
186            return Err(UnsupportedVersion::new(78, version).into());
187        }
188        write_compact_nullable_string(buf, self.group_id.as_ref())?;
189        write_compact_nullable_string(buf, self.member_id.as_ref())?;
190        write_i32(buf, self.share_session_epoch);
191        write_i32(buf, self.max_wait_ms);
192        write_i32(buf, self.min_bytes);
193        write_i32(buf, self.max_bytes);
194        write_i32(buf, self.max_records);
195        write_i32(buf, self.batch_size);
196        if version >= 2 {
197            write_i8(buf, self.share_acquire_mode);
198        } else if self.share_acquire_mode != 0i8 {
199            return Err(UnsupportedFieldVersion::new(78, "share_acquire_mode", version).into());
200        }
201        if version >= 2 {
202            write_bool(buf, self.is_renew_ack);
203        } else if self.is_renew_ack != false {
204            return Err(UnsupportedFieldVersion::new(78, "is_renew_ack", version).into());
205        }
206        write_compact_array_length(buf, self.topics.len() as i32);
207        for el in &self.topics {
208            el.write(buf, version)?;
209        }
210        write_compact_array_length(buf, self.forgotten_topics_data.len() as i32);
211        for el in &self.forgotten_topics_data {
212            el.write(buf, version)?;
213        }
214        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
215        all_tags.sort_by_key(|f| f.tag);
216        write_tagged_fields(buf, &all_tags)?;
217        Ok(())
218    }
219    pub fn encoded_len(&self, version: i16) -> Result<usize> {
220        if version < 1 || version > 2 {
221            return Err(UnsupportedVersion::new(78, version).into());
222        }
223        let mut len: usize = 0;
224        len += compact_nullable_string_len(self.group_id.as_ref())?;
225        len += compact_nullable_string_len(self.member_id.as_ref())?;
226        len += 4;
227        len += 4;
228        len += 4;
229        len += 4;
230        len += 4;
231        len += 4;
232        if version >= 2 {
233            len += 1;
234        } else if self.share_acquire_mode != 0i8 {
235            return Err(UnsupportedFieldVersion::new(78, "share_acquire_mode", version).into());
236        }
237        if version >= 2 {
238            len += 1;
239        } else if self.is_renew_ack != false {
240            return Err(UnsupportedFieldVersion::new(78, "is_renew_ack", version).into());
241        }
242        len += compact_array_length_len(self.topics.len() as i32);
243        for el in &self.topics {
244            len += el.encoded_len(version)?;
245        }
246        len += compact_array_length_len(self.forgotten_topics_data.len() as i32);
247        for el in &self.forgotten_topics_data {
248            len += el.encoded_len(version)?;
249        }
250        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
251        all_tags.sort_by_key(|f| f.tag);
252        len += tagged_fields_len(&all_tags)?;
253        Ok(len)
254    }
255}
256#[derive(Debug, Clone, PartialEq)]
257pub struct FetchTopic {
258    /// The unique topic ID.
259    pub topic_id: KafkaUuid,
260    /// The partitions to fetch.
261    pub partitions: Vec<FetchPartition>,
262    pub _unknown_tagged_fields: Vec<RawTaggedField>,
263}
264impl Default for FetchTopic {
265    fn default() -> Self {
266        Self {
267            topic_id: KafkaUuid::ZERO,
268            partitions: Vec::new(),
269            _unknown_tagged_fields: Vec::new(),
270        }
271    }
272}
273impl FetchTopic {
274    pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
275        self.topic_id = value;
276        self
277    }
278    pub fn with_partitions(mut self, value: Vec<FetchPartition>) -> Self {
279        self.partitions = value;
280        self
281    }
282    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
283        let topic_id;
284        let partitions;
285        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
286        topic_id = read_uuid(buf)?;
287        partitions = {
288            let len = read_compact_array_length(buf)?;
289            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
290            for _ in 0..len {
291                arr.push(FetchPartition::read(buf, version)?);
292            }
293            arr
294        };
295        let tagged_fields = read_tagged_fields(buf)?;
296        for field in &tagged_fields {
297            match field.tag {
298                _ => {
299                    _unknown_tagged_fields.push(field.clone());
300                },
301            }
302        }
303        Ok(Self {
304            topic_id,
305            partitions,
306            _unknown_tagged_fields,
307        })
308    }
309    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
310        write_uuid(buf, &self.topic_id);
311        write_compact_array_length(buf, self.partitions.len() as i32);
312        for el in &self.partitions {
313            el.write(buf, version)?;
314        }
315        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
316        all_tags.sort_by_key(|f| f.tag);
317        write_tagged_fields(buf, &all_tags)?;
318        Ok(())
319    }
320    pub fn encoded_len(&self, version: i16) -> Result<usize> {
321        let mut len: usize = 0;
322        len += 16;
323        len += compact_array_length_len(self.partitions.len() as i32);
324        for el in &self.partitions {
325            len += el.encoded_len(version)?;
326        }
327        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
328        all_tags.sort_by_key(|f| f.tag);
329        len += tagged_fields_len(&all_tags)?;
330        Ok(len)
331    }
332}
333#[derive(Debug, Clone, PartialEq)]
334pub struct FetchPartition {
335    /// The partition index.
336    pub partition_index: i32,
337    /// The maximum bytes to fetch from this partition. 0 when only acknowledgement with no
338    /// fetching is required. See KIP-74 for cases where this limit may not be honored.
339    pub partition_max_bytes: i32,
340    /// Record batches to acknowledge.
341    pub acknowledgement_batches: Vec<AcknowledgementBatch>,
342    pub _unknown_tagged_fields: Vec<RawTaggedField>,
343}
344impl Default for FetchPartition {
345    fn default() -> Self {
346        Self {
347            partition_index: 0_i32,
348            partition_max_bytes: 0_i32,
349            acknowledgement_batches: Vec::new(),
350            _unknown_tagged_fields: Vec::new(),
351        }
352    }
353}
354impl FetchPartition {
355    pub fn with_partition_index(mut self, value: i32) -> Self {
356        self.partition_index = value;
357        self
358    }
359    pub fn with_partition_max_bytes(mut self, value: i32) -> Self {
360        self.partition_max_bytes = value;
361        self
362    }
363    pub fn with_acknowledgement_batches(mut self, value: Vec<AcknowledgementBatch>) -> Self {
364        self.acknowledgement_batches = value;
365        self
366    }
367    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
368        let partition_index;
369        let partition_max_bytes = 0_i32;
370        let acknowledgement_batches;
371        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
372        partition_index = read_i32(buf)?;
373        acknowledgement_batches = {
374            let len = read_compact_array_length(buf)?;
375            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
376            for _ in 0..len {
377                arr.push(AcknowledgementBatch::read(buf, version)?);
378            }
379            arr
380        };
381        let tagged_fields = read_tagged_fields(buf)?;
382        for field in &tagged_fields {
383            match field.tag {
384                _ => {
385                    _unknown_tagged_fields.push(field.clone());
386                },
387            }
388        }
389        Ok(Self {
390            partition_index,
391            partition_max_bytes,
392            acknowledgement_batches,
393            _unknown_tagged_fields,
394        })
395    }
396    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
397        write_i32(buf, self.partition_index);
398        write_compact_array_length(buf, self.acknowledgement_batches.len() as i32);
399        for el in &self.acknowledgement_batches {
400            el.write(buf, version)?;
401        }
402        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
403        all_tags.sort_by_key(|f| f.tag);
404        write_tagged_fields(buf, &all_tags)?;
405        Ok(())
406    }
407    pub fn encoded_len(&self, version: i16) -> Result<usize> {
408        let mut len: usize = 0;
409        len += 4;
410        len += compact_array_length_len(self.acknowledgement_batches.len() as i32);
411        for el in &self.acknowledgement_batches {
412            len += el.encoded_len(version)?;
413        }
414        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
415        all_tags.sort_by_key(|f| f.tag);
416        len += tagged_fields_len(&all_tags)?;
417        Ok(len)
418    }
419}
420#[derive(Debug, Clone, PartialEq)]
421pub struct AcknowledgementBatch {
422    /// First offset of batch of records to acknowledge.
423    pub first_offset: i64,
424    /// Last offset (inclusive) of batch of records to acknowledge.
425    pub last_offset: i64,
426    /// Array of acknowledge types - 0:Gap,1:Accept,2:Release,3:Reject,4:Renew.
427    pub acknowledge_types: Vec<i8>,
428    pub _unknown_tagged_fields: Vec<RawTaggedField>,
429}
430impl Default for AcknowledgementBatch {
431    fn default() -> Self {
432        Self {
433            first_offset: 0_i64,
434            last_offset: 0_i64,
435            acknowledge_types: Vec::new(),
436            _unknown_tagged_fields: Vec::new(),
437        }
438    }
439}
440impl AcknowledgementBatch {
441    pub fn with_first_offset(mut self, value: i64) -> Self {
442        self.first_offset = value;
443        self
444    }
445    pub fn with_last_offset(mut self, value: i64) -> Self {
446        self.last_offset = value;
447        self
448    }
449    pub fn with_acknowledge_types(mut self, value: Vec<i8>) -> Self {
450        self.acknowledge_types = value;
451        self
452    }
453    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
454        let first_offset;
455        let last_offset;
456        let acknowledge_types;
457        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
458        first_offset = read_i64(buf)?;
459        last_offset = read_i64(buf)?;
460        acknowledge_types = {
461            let len = read_compact_array_length(buf)?;
462            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
463            for _ in 0..len {
464                arr.push(read_i8(buf)?);
465            }
466            arr
467        };
468        let tagged_fields = read_tagged_fields(buf)?;
469        for field in &tagged_fields {
470            match field.tag {
471                _ => {
472                    _unknown_tagged_fields.push(field.clone());
473                },
474            }
475        }
476        Ok(Self {
477            first_offset,
478            last_offset,
479            acknowledge_types,
480            _unknown_tagged_fields,
481        })
482    }
483    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
484        write_i64(buf, self.first_offset);
485        write_i64(buf, self.last_offset);
486        write_compact_array_length(buf, self.acknowledge_types.len() as i32);
487        for el in &self.acknowledge_types {
488            write_i8(buf, *el);
489        }
490        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
491        all_tags.sort_by_key(|f| f.tag);
492        write_tagged_fields(buf, &all_tags)?;
493        Ok(())
494    }
495    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
496        let mut len: usize = 0;
497        len += 8;
498        len += 8;
499        len += compact_array_length_len(self.acknowledge_types.len() as i32);
500        len += self.acknowledge_types.len() * 1usize;
501        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
502        all_tags.sort_by_key(|f| f.tag);
503        len += tagged_fields_len(&all_tags)?;
504        Ok(len)
505    }
506}
507#[derive(Debug, Clone, PartialEq)]
508pub struct ForgottenTopic {
509    /// The unique topic ID.
510    pub topic_id: KafkaUuid,
511    /// The partitions indexes to forget.
512    pub partitions: Vec<i32>,
513    pub _unknown_tagged_fields: Vec<RawTaggedField>,
514}
515impl Default for ForgottenTopic {
516    fn default() -> Self {
517        Self {
518            topic_id: KafkaUuid::ZERO,
519            partitions: Vec::new(),
520            _unknown_tagged_fields: Vec::new(),
521        }
522    }
523}
524impl ForgottenTopic {
525    pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
526        self.topic_id = value;
527        self
528    }
529    pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
530        self.partitions = value;
531        self
532    }
533    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
534        let topic_id;
535        let partitions;
536        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
537        topic_id = read_uuid(buf)?;
538        partitions = {
539            let len = read_compact_array_length(buf)?;
540            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
541            for _ in 0..len {
542                arr.push(read_i32(buf)?);
543            }
544            arr
545        };
546        let tagged_fields = read_tagged_fields(buf)?;
547        for field in &tagged_fields {
548            match field.tag {
549                _ => {
550                    _unknown_tagged_fields.push(field.clone());
551                },
552            }
553        }
554        Ok(Self {
555            topic_id,
556            partitions,
557            _unknown_tagged_fields,
558        })
559    }
560    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
561        write_uuid(buf, &self.topic_id);
562        write_compact_array_length(buf, self.partitions.len() as i32);
563        for el in &self.partitions {
564            write_i32(buf, *el);
565        }
566        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
567        all_tags.sort_by_key(|f| f.tag);
568        write_tagged_fields(buf, &all_tags)?;
569        Ok(())
570    }
571    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
572        let mut len: usize = 0;
573        len += 16;
574        len += compact_array_length_len(self.partitions.len() as i32);
575        len += self.partitions.len() * 4usize;
576        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
577        all_tags.sort_by_key(|f| f.tag);
578        len += tagged_fields_len(&all_tags)?;
579        Ok(len)
580    }
581}