Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i64, put_bool, put_i16, put_i64};
6use crate::primitives::string_bytes::{
7    compact_string_len, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 24;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 5;
16pub const FLEXIBLE_MIN: i16 = 3;
17
18#[inline]
19fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct AddPartitionsToTxnRequest < 'a > { pub transactions : Vec < AddPartitionsToTxnTransaction <'a >> , pub v3_and_below_transactional_id : &'a str , pub v3_and_below_producer_id : i64 , pub v3_and_below_producer_epoch : i16 , pub v3_and_below_topics : Vec < super :: common :: add_partitions_to_txn_request :: add_partitions_to_txn_topic :: AddPartitionsToTxnTopic <'a >> , pub unknown_tagged_fields : UnknownTaggedFields , }
25impl AddPartitionsToTxnRequest<'_> {
26    pub fn to_owned(
27        &self,
28    ) -> crate::owned::add_partitions_to_txn_request::AddPartitionsToTxnRequest {
29        crate::owned::add_partitions_to_txn_request::AddPartitionsToTxnRequest {
30            transactions: (self.transactions).iter().map(AddPartitionsToTxnTransaction::to_owned).collect(),
31            v3_and_below_transactional_id: (self.v3_and_below_transactional_id).to_string(),
32            v3_and_below_producer_id: (self.v3_and_below_producer_id),
33            v3_and_below_producer_epoch: (self.v3_and_below_producer_epoch),
34            v3_and_below_topics: (self.v3_and_below_topics)
35                .iter()
36                .map(super::common::add_partitions_to_txn_request::add_partitions_to_txn_topic::AddPartitionsToTxnTopic::to_owned)
37                .collect(),
38            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
39        }
40    }
41}
42impl Encode for AddPartitionsToTxnRequest<'_> {
43    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
44        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
45            return Err(ProtocolError::UnsupportedVersion {
46                api_key: API_KEY,
47                version,
48            });
49        }
50        let flex = is_flexible(version);
51        if version >= 4 {
52            {
53                crate::primitives::array::put_array_len(buf, (self.transactions).len(), flex);
54                for it in &self.transactions {
55                    it.encode(buf, version)?;
56                }
57            }
58        }
59        if (0..=3).contains(&version) {
60            if flex {
61                put_compact_string(buf, self.v3_and_below_transactional_id);
62            } else {
63                put_string(buf, self.v3_and_below_transactional_id);
64            }
65        }
66        if (0..=3).contains(&version) {
67            put_i64(buf, self.v3_and_below_producer_id);
68        }
69        if (0..=3).contains(&version) {
70            put_i16(buf, self.v3_and_below_producer_epoch);
71        }
72        if (0..=3).contains(&version) {
73            {
74                crate::primitives::array::put_array_len(
75                    buf,
76                    (self.v3_and_below_topics).len(),
77                    flex,
78                );
79                for it in &self.v3_and_below_topics {
80                    it.encode(buf, version)?;
81                }
82            }
83        }
84        if flex {
85            let tagged = WriteTaggedFields::new();
86            tagged.write(buf, &self.unknown_tagged_fields);
87        }
88        Ok(())
89    }
90    fn encoded_len(&self, version: i16) -> usize {
91        let flex = is_flexible(version);
92        let mut n: usize = 0;
93        if version >= 4 {
94            n += {
95                let prefix =
96                    crate::primitives::array::array_len_prefix_len((self.transactions).len(), flex);
97                let body: usize = (self.transactions)
98                    .iter()
99                    .map(|it| it.encoded_len(version))
100                    .sum();
101                prefix + body
102            };
103        }
104        if (0..=3).contains(&version) {
105            n += if flex {
106                compact_string_len(self.v3_and_below_transactional_id)
107            } else {
108                string_len(self.v3_and_below_transactional_id)
109            };
110        }
111        if (0..=3).contains(&version) {
112            n += 8;
113        }
114        if (0..=3).contains(&version) {
115            n += 2;
116        }
117        if (0..=3).contains(&version) {
118            n += {
119                let prefix = crate::primitives::array::array_len_prefix_len(
120                    (self.v3_and_below_topics).len(),
121                    flex,
122                );
123                let body: usize = (self.v3_and_below_topics)
124                    .iter()
125                    .map(|it| it.encoded_len(version))
126                    .sum();
127                prefix + body
128            };
129        }
130        if flex {
131            let known_pairs: Vec<(u32, usize)> = Vec::new();
132            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
133        }
134        n
135    }
136}
137impl<'de> DecodeBorrow<'de> for AddPartitionsToTxnRequest<'de> {
138    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
139        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
140            return Err(ProtocolError::UnsupportedVersion {
141                api_key: API_KEY,
142                version,
143            });
144        }
145        let flex = is_flexible(version);
146        let mut out = Self::default();
147        if version >= 4 {
148            out.transactions = {
149                let n = crate::primitives::array::get_array_len(buf, flex)?;
150                let mut v = Vec::with_capacity(n);
151                for _ in 0..n {
152                    v.push(AddPartitionsToTxnTransaction::decode_borrow(buf, version)?);
153                }
154                v
155            };
156        }
157        if (0..=3).contains(&version) {
158            out.v3_and_below_transactional_id = if flex {
159                get_compact_string_borrowed(buf)?
160            } else {
161                get_string_borrowed(buf)?
162            };
163        }
164        if (0..=3).contains(&version) {
165            out.v3_and_below_producer_id = get_i64(buf)?;
166        }
167        if (0..=3).contains(&version) {
168            out.v3_and_below_producer_epoch = get_i16(buf)?;
169        }
170        if (0..=3).contains(&version) {
171            out.v3_and_below_topics = {
172                let n = crate::primitives::array::get_array_len(buf, flex)?;
173                let mut v = Vec::with_capacity(n);
174                for _ in 0..n {
175                    v . push (super :: common :: add_partitions_to_txn_request :: add_partitions_to_txn_topic :: AddPartitionsToTxnTopic :: decode_borrow (buf , version) ?) ;
176                }
177                v
178            };
179        }
180        if flex {
181            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
182        }
183        Ok(out)
184    }
185}
186#[cfg(test)]
187impl AddPartitionsToTxnRequest<'_> {
188    #[must_use]
189    pub fn populated(version: i16) -> Self {
190        let mut m = Self::default();
191        if version >= 4 {
192            m.transactions = vec![AddPartitionsToTxnTransaction::populated(version)];
193        }
194        if (0..=3).contains(&version) {
195            m.v3_and_below_transactional_id = "x";
196        }
197        if (0..=3).contains(&version) {
198            m.v3_and_below_producer_id = 1i64;
199        }
200        if (0..=3).contains(&version) {
201            m.v3_and_below_producer_epoch = 1i16;
202        }
203        if (0..=3).contains(&version) {
204            m . v3_and_below_topics = vec ! [super :: common :: add_partitions_to_txn_request :: add_partitions_to_txn_topic :: AddPartitionsToTxnTopic :: populated (version)] ;
205        }
206        m
207    }
208}
209#[derive(Debug, Clone, PartialEq, Eq, Default)]
210pub struct AddPartitionsToTxnTransaction < 'a > { pub transactional_id : &'a str , pub producer_id : i64 , pub producer_epoch : i16 , pub verify_only : bool , pub topics : Vec < super :: common :: add_partitions_to_txn_request :: add_partitions_to_txn_topic :: AddPartitionsToTxnTopic <'a >> , pub unknown_tagged_fields : UnknownTaggedFields , }
211impl AddPartitionsToTxnTransaction<'_> {
212    pub fn to_owned(
213        &self,
214    ) -> crate::owned::add_partitions_to_txn_request::AddPartitionsToTxnTransaction {
215        crate::owned::add_partitions_to_txn_request::AddPartitionsToTxnTransaction {
216            transactional_id: (self.transactional_id).to_string(),
217            producer_id: (self.producer_id),
218            producer_epoch: (self.producer_epoch),
219            verify_only: (self.verify_only),
220            topics: (self.topics).iter().map(super::common::add_partitions_to_txn_request::add_partitions_to_txn_topic::AddPartitionsToTxnTopic::to_owned).collect(),
221            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
222        }
223    }
224}
225impl Encode for AddPartitionsToTxnTransaction<'_> {
226    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
227        let flex = version >= 3;
228        if version >= 4 {
229            if flex {
230                put_compact_string(buf, self.transactional_id);
231            } else {
232                put_string(buf, self.transactional_id);
233            }
234        }
235        if version >= 4 {
236            put_i64(buf, self.producer_id);
237        }
238        if version >= 4 {
239            put_i16(buf, self.producer_epoch);
240        }
241        if version >= 4 {
242            put_bool(buf, self.verify_only);
243        }
244        if version >= 4 {
245            {
246                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
247                for it in &self.topics {
248                    it.encode(buf, version)?;
249                }
250            }
251        }
252        if flex {
253            let tagged = WriteTaggedFields::new();
254            tagged.write(buf, &self.unknown_tagged_fields);
255        }
256        Ok(())
257    }
258    fn encoded_len(&self, version: i16) -> usize {
259        let flex = version >= 3;
260        let mut n: usize = 0;
261        if version >= 4 {
262            n += if flex {
263                compact_string_len(self.transactional_id)
264            } else {
265                string_len(self.transactional_id)
266            };
267        }
268        if version >= 4 {
269            n += 8;
270        }
271        if version >= 4 {
272            n += 2;
273        }
274        if version >= 4 {
275            n += 1;
276        }
277        if version >= 4 {
278            n += {
279                let prefix =
280                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
281                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
282                prefix + body
283            };
284        }
285        if flex {
286            let known_pairs: Vec<(u32, usize)> = Vec::new();
287            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
288        }
289        n
290    }
291}
292impl<'de> DecodeBorrow<'de> for AddPartitionsToTxnTransaction<'de> {
293    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
294        let flex = version >= 3;
295        let mut out = Self::default();
296        if version >= 4 {
297            out.transactional_id = if flex {
298                get_compact_string_borrowed(buf)?
299            } else {
300                get_string_borrowed(buf)?
301            };
302        }
303        if version >= 4 {
304            out.producer_id = get_i64(buf)?;
305        }
306        if version >= 4 {
307            out.producer_epoch = get_i16(buf)?;
308        }
309        if version >= 4 {
310            out.verify_only = get_bool(buf)?;
311        }
312        if version >= 4 {
313            out.topics = {
314                let n = crate::primitives::array::get_array_len(buf, flex)?;
315                let mut v = Vec::with_capacity(n);
316                for _ in 0..n {
317                    v . push (super :: common :: add_partitions_to_txn_request :: add_partitions_to_txn_topic :: AddPartitionsToTxnTopic :: decode_borrow (buf , version) ?) ;
318                }
319                v
320            };
321        }
322        if flex {
323            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
324        }
325        Ok(out)
326    }
327}
328#[cfg(test)]
329impl AddPartitionsToTxnTransaction<'_> {
330    #[must_use]
331    pub fn populated(version: i16) -> Self {
332        let mut m = Self::default();
333        if version >= 4 {
334            m.transactional_id = "x";
335        }
336        if version >= 4 {
337            m.producer_id = 1i64;
338        }
339        if version >= 4 {
340            m.producer_epoch = 1i16;
341        }
342        if version >= 4 {
343            m.verify_only = true;
344        }
345        if version >= 4 {
346            m . topics = vec ! [super :: common :: add_partitions_to_txn_request :: add_partitions_to_txn_topic :: AddPartitionsToTxnTopic :: populated (version)] ;
347        }
348        m
349    }
350}