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::{
10    get_compact_string_borrowed, get_string_borrowed,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 24;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 5;
18pub const FLEXIBLE_MIN: i16 = 3;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct AddPartitionsToTxnRequest<'a> {
25    pub transactions: Vec<AddPartitionsToTxnTransaction<'a>>,
26    pub v3_and_below_transactional_id: &'a str,
27    pub v3_and_below_producer_id: i64,
28    pub v3_and_below_producer_epoch: i16,
29    pub v3_and_below_topics: Vec<super::common::add_partitions_to_txn_topic::AddPartitionsToTxnTopic<'a>>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl<'a> Default for AddPartitionsToTxnRequest<'a> {
34    fn default() -> Self {
35        Self {
36            transactions: Vec::new(),
37            v3_and_below_transactional_id: "",
38            v3_and_below_producer_id: 0i64,
39            v3_and_below_producer_epoch: 0i16,
40            v3_and_below_topics: Vec::new(),
41            unknown_tagged_fields: Default::default(),
42        }
43    }
44}
45
46impl<'a> AddPartitionsToTxnRequest<'a> {
47    pub fn to_owned(&self) -> crate::owned::add_partitions_to_txn_request::AddPartitionsToTxnRequest {
48        crate::owned::add_partitions_to_txn_request::AddPartitionsToTxnRequest {
49            transactions: (self.transactions).iter().map(|it| it.to_owned()).collect(),
50            v3_and_below_transactional_id: (self.v3_and_below_transactional_id).to_string(),
51            v3_and_below_producer_id: (self.v3_and_below_producer_id),
52            v3_and_below_producer_epoch: (self.v3_and_below_producer_epoch),
53            v3_and_below_topics: (self.v3_and_below_topics).iter().map(|it| it.to_owned()).collect(),
54            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
55        }
56    }
57}
58
59impl<'a> Encode for AddPartitionsToTxnRequest<'a> {
60    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
61        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
62            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
63        }
64        let flex = is_flexible(version);
65        if version >= 4 { { crate::primitives::array::put_array_len(buf, (self.transactions).len(), flex); for it in &self.transactions { it.encode(buf, version)?; } } }
66        if version >= 0 && version <= 3 { if flex { put_compact_string(buf, self.v3_and_below_transactional_id) } else { put_string(buf, self.v3_and_below_transactional_id) } }
67        if version >= 0 && version <= 3 { put_i64(buf, self.v3_and_below_producer_id) }
68        if version >= 0 && version <= 3 { put_i16(buf, self.v3_and_below_producer_epoch) }
69        if version >= 0 && version <= 3 { { crate::primitives::array::put_array_len(buf, (self.v3_and_below_topics).len(), flex); for it in &self.v3_and_below_topics { it.encode(buf, version)?; } } }
70        if flex {
71            let tagged = WriteTaggedFields::new();
72            tagged.write(buf, &self.unknown_tagged_fields);
73        }
74        Ok(())
75    }
76    fn encoded_len(&self, version: i16) -> usize {
77        let flex = is_flexible(version);
78        let mut n: usize = 0;
79        if version >= 4 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.transactions).len(), flex); let body: usize = (self.transactions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
80        if version >= 0 && version <= 3 { n += if flex { compact_string_len(self.v3_and_below_transactional_id) } else { string_len(self.v3_and_below_transactional_id) }; }
81        if version >= 0 && version <= 3 { n += 8; }
82        if version >= 0 && version <= 3 { n += 2; }
83        if version >= 0 && version <= 3 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.v3_and_below_topics).len(), flex); let body: usize = (self.v3_and_below_topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
84        if flex {
85            let known_pairs: Vec<(u32, usize)> = Vec::new();
86            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
87        }
88        n
89    }
90}
91
92impl<'de> DecodeBorrow<'de> for AddPartitionsToTxnRequest<'de> {
93    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
94        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
95            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
96        }
97        let flex = is_flexible(version);
98        let mut out = Self::default();
99        if version >= 4 { out.transactions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AddPartitionsToTxnTransaction::decode_borrow(buf, version)?); } v }; }
100        if version >= 0 && version <= 3 { out.v3_and_below_transactional_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
101        if version >= 0 && version <= 3 { out.v3_and_below_producer_id = get_i64(buf)?; }
102        if version >= 0 && version <= 3 { out.v3_and_below_producer_epoch = get_i16(buf)?; }
103        if version >= 0 && version <= 3 { out.v3_and_below_topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::add_partitions_to_txn_topic::AddPartitionsToTxnTopic::decode_borrow(buf, version)?); } v }; }
104        if flex {
105            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
106                Ok(false)
107            })?;
108        }
109        Ok(out)
110    }
111}
112
113#[derive(Debug, Clone, PartialEq, Eq)]
114pub struct AddPartitionsToTxnTransaction<'a> {
115    pub transactional_id: &'a str,
116    pub producer_id: i64,
117    pub producer_epoch: i16,
118    pub verify_only: bool,
119    pub topics: Vec<super::common::add_partitions_to_txn_topic::AddPartitionsToTxnTopic<'a>>,
120    pub unknown_tagged_fields: UnknownTaggedFields,
121}
122
123impl<'a> Default for AddPartitionsToTxnTransaction<'a> {
124    fn default() -> Self {
125        Self {
126            transactional_id: "",
127            producer_id: 0i64,
128            producer_epoch: 0i16,
129            verify_only: false,
130            topics: Vec::new(),
131            unknown_tagged_fields: Default::default(),
132        }
133    }
134}
135
136impl<'a> AddPartitionsToTxnTransaction<'a> {
137    pub fn to_owned(&self) -> crate::owned::add_partitions_to_txn_request::AddPartitionsToTxnTransaction {
138        crate::owned::add_partitions_to_txn_request::AddPartitionsToTxnTransaction {
139            transactional_id: (self.transactional_id).to_string(),
140            producer_id: (self.producer_id),
141            producer_epoch: (self.producer_epoch),
142            verify_only: (self.verify_only),
143            topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
144            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
145        }
146    }
147}
148
149impl<'a> Encode for AddPartitionsToTxnTransaction<'a> {
150    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
151        let flex = version >= 3;
152        if version >= 4 { if flex { put_compact_string(buf, self.transactional_id) } else { put_string(buf, self.transactional_id) } }
153        if version >= 4 { put_i64(buf, self.producer_id) }
154        if version >= 4 { put_i16(buf, self.producer_epoch) }
155        if version >= 4 { put_bool(buf, self.verify_only) }
156        if version >= 4 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
157        if flex {
158            let tagged = WriteTaggedFields::new();
159            tagged.write(buf, &self.unknown_tagged_fields);
160        }
161        Ok(())
162    }
163    fn encoded_len(&self, version: i16) -> usize {
164        let flex = version >= 3;
165        let mut n: usize = 0;
166        if version >= 4 { n += if flex { compact_string_len(self.transactional_id) } else { string_len(self.transactional_id) }; }
167        if version >= 4 { n += 8; }
168        if version >= 4 { n += 2; }
169        if version >= 4 { n += 1; }
170        if version >= 4 { 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 }; }
171        if flex {
172            let known_pairs: Vec<(u32, usize)> = Vec::new();
173            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
174        }
175        n
176    }
177}
178
179impl<'de> DecodeBorrow<'de> for AddPartitionsToTxnTransaction<'de> {
180    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
181        let flex = version >= 3;
182        let mut out = Self::default();
183        if version >= 4 { out.transactional_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
184        if version >= 4 { out.producer_id = get_i64(buf)?; }
185        if version >= 4 { out.producer_epoch = get_i16(buf)?; }
186        if version >= 4 { out.verify_only = get_bool(buf)?; }
187        if version >= 4 { 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(super::common::add_partitions_to_txn_topic::AddPartitionsToTxnTopic::decode_borrow(buf, version)?); } v }; }
188        if flex {
189            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
190                Ok(false)
191            })?;
192        }
193        Ok(out)
194    }
195}