Skip to main content

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

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