Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, 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,
9    string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13    get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 28;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 5;
21pub const FLEXIBLE_MIN: i16 = 3;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct TxnOffsetCommitRequest<'a> {
28    pub transactional_id: &'a str,
29    pub group_id: &'a str,
30    pub producer_id: i64,
31    pub producer_epoch: i16,
32    pub generation_id: i32,
33    pub member_id: &'a str,
34    pub group_instance_id: Option<&'a str>,
35    pub topics: Vec<TxnOffsetCommitRequestTopic<'a>>,
36    pub unknown_tagged_fields: UnknownTaggedFields,
37}
38
39impl<'a> Default for TxnOffsetCommitRequest<'a> {
40    fn default() -> Self {
41        Self {
42            transactional_id: "",
43            group_id: "",
44            producer_id: 0i64,
45            producer_epoch: 0i16,
46            generation_id: -1i32,
47            member_id: "",
48            group_instance_id: None,
49            topics: Vec::new(),
50            unknown_tagged_fields: Default::default(),
51        }
52    }
53}
54
55impl<'a> TxnOffsetCommitRequest<'a> {
56    pub fn to_owned(&self) -> crate::owned::txn_offset_commit_request::TxnOffsetCommitRequest {
57        crate::owned::txn_offset_commit_request::TxnOffsetCommitRequest {
58            transactional_id: (self.transactional_id).to_string(),
59            group_id: (self.group_id).to_string(),
60            producer_id: (self.producer_id),
61            producer_epoch: (self.producer_epoch),
62            generation_id: (self.generation_id),
63            member_id: (self.member_id).to_string(),
64            group_instance_id: (self.group_instance_id).map(|s| s.to_string()),
65            topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
66            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
67        }
68    }
69}
70
71impl<'a> Encode for TxnOffsetCommitRequest<'a> {
72    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
73        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
74            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
75        }
76        let flex = is_flexible(version);
77        if version >= 0 { if flex { put_compact_string(buf, self.transactional_id) } else { put_string(buf, self.transactional_id) } }
78        if version >= 0 { if flex { put_compact_string(buf, self.group_id) } else { put_string(buf, self.group_id) } }
79        if version >= 0 { put_i64(buf, self.producer_id) }
80        if version >= 0 { put_i16(buf, self.producer_epoch) }
81        if version >= 3 { put_i32(buf, self.generation_id) }
82        if version >= 3 { if flex { put_compact_string(buf, self.member_id) } else { put_string(buf, self.member_id) } }
83        if version >= 3 { if flex { put_compact_nullable_string(buf, self.group_instance_id) } else { put_nullable_string(buf, self.group_instance_id) } }
84        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
85        if flex {
86            let tagged = WriteTaggedFields::new();
87            tagged.write(buf, &self.unknown_tagged_fields);
88        }
89        Ok(())
90    }
91    fn encoded_len(&self, version: i16) -> usize {
92        let flex = is_flexible(version);
93        let mut n: usize = 0;
94        if version >= 0 { n += if flex { compact_string_len(self.transactional_id) } else { string_len(self.transactional_id) }; }
95        if version >= 0 { n += if flex { compact_string_len(self.group_id) } else { string_len(self.group_id) }; }
96        if version >= 0 { n += 8; }
97        if version >= 0 { n += 2; }
98        if version >= 3 { n += 4; }
99        if version >= 3 { n += if flex { compact_string_len(self.member_id) } else { string_len(self.member_id) }; }
100        if version >= 3 { n += if flex { compact_nullable_string_len(self.group_instance_id) } else { nullable_string_len(self.group_instance_id) }; }
101        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
102        if flex {
103            let known_pairs: Vec<(u32, usize)> = Vec::new();
104            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
105        }
106        n
107    }
108}
109
110impl<'de> DecodeBorrow<'de> for TxnOffsetCommitRequest<'de> {
111    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
112        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
113            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
114        }
115        let flex = is_flexible(version);
116        let mut out = Self::default();
117        if version >= 0 { out.transactional_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
118        if version >= 0 { out.group_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
119        if version >= 0 { out.producer_id = get_i64(buf)?; }
120        if version >= 0 { out.producer_epoch = get_i16(buf)?; }
121        if version >= 3 { out.generation_id = get_i32(buf)?; }
122        if version >= 3 { out.member_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
123        if version >= 3 { out.group_instance_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
124        if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TxnOffsetCommitRequestTopic::decode_borrow(buf, version)?); } v }; }
125        if flex {
126            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
127                Ok(false)
128            })?;
129        }
130        Ok(out)
131    }
132}
133
134#[derive(Debug, Clone, PartialEq, Eq)]
135pub struct TxnOffsetCommitRequestTopic<'a> {
136    pub name: &'a str,
137    pub partitions: Vec<TxnOffsetCommitRequestPartition<'a>>,
138    pub unknown_tagged_fields: UnknownTaggedFields,
139}
140
141impl<'a> Default for TxnOffsetCommitRequestTopic<'a> {
142    fn default() -> Self {
143        Self {
144            name: "",
145            partitions: Vec::new(),
146            unknown_tagged_fields: Default::default(),
147        }
148    }
149}
150
151impl<'a> TxnOffsetCommitRequestTopic<'a> {
152    pub fn to_owned(&self) -> crate::owned::txn_offset_commit_request::TxnOffsetCommitRequestTopic {
153        crate::owned::txn_offset_commit_request::TxnOffsetCommitRequestTopic {
154            name: (self.name).to_string(),
155            partitions: (self.partitions).iter().map(|it| it.to_owned()).collect(),
156            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
157        }
158    }
159}
160
161impl<'a> Encode for TxnOffsetCommitRequestTopic<'a> {
162    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
163        let flex = version >= 3;
164        if version >= 0 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
165        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
166        if flex {
167            let tagged = WriteTaggedFields::new();
168            tagged.write(buf, &self.unknown_tagged_fields);
169        }
170        Ok(())
171    }
172    fn encoded_len(&self, version: i16) -> usize {
173        let flex = version >= 3;
174        let mut n: usize = 0;
175        if version >= 0 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
176        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
177        if flex {
178            let known_pairs: Vec<(u32, usize)> = Vec::new();
179            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
180        }
181        n
182    }
183}
184
185impl<'de> DecodeBorrow<'de> for TxnOffsetCommitRequestTopic<'de> {
186    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
187        let flex = version >= 3;
188        let mut out = Self::default();
189        if version >= 0 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
190        if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TxnOffsetCommitRequestPartition::decode_borrow(buf, version)?); } v }; }
191        if flex {
192            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
193                Ok(false)
194            })?;
195        }
196        Ok(out)
197    }
198}
199
200#[derive(Debug, Clone, PartialEq, Eq)]
201pub struct TxnOffsetCommitRequestPartition<'a> {
202    pub partition_index: i32,
203    pub committed_offset: i64,
204    pub committed_leader_epoch: i32,
205    pub committed_metadata: Option<&'a str>,
206    pub unknown_tagged_fields: UnknownTaggedFields,
207}
208
209impl<'a> Default for TxnOffsetCommitRequestPartition<'a> {
210    fn default() -> Self {
211        Self {
212            partition_index: 0i32,
213            committed_offset: 0i64,
214            committed_leader_epoch: -1i32,
215            committed_metadata: None,
216            unknown_tagged_fields: Default::default(),
217        }
218    }
219}
220
221impl<'a> TxnOffsetCommitRequestPartition<'a> {
222    pub fn to_owned(&self) -> crate::owned::txn_offset_commit_request::TxnOffsetCommitRequestPartition {
223        crate::owned::txn_offset_commit_request::TxnOffsetCommitRequestPartition {
224            partition_index: (self.partition_index),
225            committed_offset: (self.committed_offset),
226            committed_leader_epoch: (self.committed_leader_epoch),
227            committed_metadata: (self.committed_metadata).map(|s| s.to_string()),
228            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
229        }
230    }
231}
232
233impl<'a> Encode for TxnOffsetCommitRequestPartition<'a> {
234    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
235        let flex = version >= 3;
236        if version >= 0 { put_i32(buf, self.partition_index) }
237        if version >= 0 { put_i64(buf, self.committed_offset) }
238        if version >= 2 { put_i32(buf, self.committed_leader_epoch) }
239        if version >= 0 { if flex { put_compact_nullable_string(buf, self.committed_metadata) } else { put_nullable_string(buf, self.committed_metadata) } }
240        if flex {
241            let tagged = WriteTaggedFields::new();
242            tagged.write(buf, &self.unknown_tagged_fields);
243        }
244        Ok(())
245    }
246    fn encoded_len(&self, version: i16) -> usize {
247        let flex = version >= 3;
248        let mut n: usize = 0;
249        if version >= 0 { n += 4; }
250        if version >= 0 { n += 8; }
251        if version >= 2 { n += 4; }
252        if version >= 0 { n += if flex { compact_nullable_string_len(self.committed_metadata) } else { nullable_string_len(self.committed_metadata) }; }
253        if flex {
254            let known_pairs: Vec<(u32, usize)> = Vec::new();
255            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
256        }
257        n
258    }
259}
260
261impl<'de> DecodeBorrow<'de> for TxnOffsetCommitRequestPartition<'de> {
262    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
263        let flex = version >= 3;
264        let mut out = Self::default();
265        if version >= 0 { out.partition_index = get_i32(buf)?; }
266        if version >= 0 { out.committed_offset = get_i64(buf)?; }
267        if version >= 2 { out.committed_leader_epoch = get_i32(buf)?; }
268        if version >= 0 { out.committed_metadata = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
269        if flex {
270            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
271                Ok(false)
272            })?;
273        }
274        Ok(out)
275    }
276}