Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
OffsetCommitRequest.borrowed.rs

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