Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
WriteTxnMarkersRequest.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_i32, get_i64, get_i8, put_bool, put_i16, put_i32, put_i64, put_i8};
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 = 27;
16pub const MIN_VERSION: i16 = 1;
17pub const MAX_VERSION: i16 = 2;
18pub const FLEXIBLE_MIN: i16 = 1;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct WriteTxnMarkersRequest<'a> {
25    pub markers: Vec<WritableTxnMarker<'a>>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28
29impl<'a> Default for WriteTxnMarkersRequest<'a> {
30    fn default() -> Self {
31        Self {
32            markers: Vec::new(),
33            unknown_tagged_fields: Default::default(),
34        }
35    }
36}
37
38impl<'a> WriteTxnMarkersRequest<'a> {
39    pub fn to_owned(&self) -> crate::owned::write_txn_markers_request::WriteTxnMarkersRequest {
40        crate::owned::write_txn_markers_request::WriteTxnMarkersRequest {
41            markers: (self.markers).iter().map(|it| it.to_owned()).collect(),
42            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
43        }
44    }
45}
46
47impl<'a> Encode for WriteTxnMarkersRequest<'a> {
48    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
49        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
50            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
51        }
52        let flex = is_flexible(version);
53        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.markers).len(), flex); for it in &self.markers { it.encode(buf, version)?; } } }
54        if flex {
55            let tagged = WriteTaggedFields::new();
56            tagged.write(buf, &self.unknown_tagged_fields);
57        }
58        Ok(())
59    }
60    fn encoded_len(&self, version: i16) -> usize {
61        let flex = is_flexible(version);
62        let mut n: usize = 0;
63        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.markers).len(), flex); let body: usize = (self.markers).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
64        if flex {
65            let known_pairs: Vec<(u32, usize)> = Vec::new();
66            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
67        }
68        n
69    }
70}
71
72impl<'de> DecodeBorrow<'de> for WriteTxnMarkersRequest<'de> {
73    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
74        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
75            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
76        }
77        let flex = is_flexible(version);
78        let mut out = Self::default();
79        if version >= 0 { out.markers = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(WritableTxnMarker::decode_borrow(buf, version)?); } v }; }
80        if flex {
81            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
82                Ok(false)
83            })?;
84        }
85        Ok(out)
86    }
87}
88
89#[derive(Debug, Clone, PartialEq, Eq)]
90pub struct WritableTxnMarker<'a> {
91    pub producer_id: i64,
92    pub producer_epoch: i16,
93    pub transaction_result: bool,
94    pub topics: Vec<WritableTxnMarkerTopic<'a>>,
95    pub coordinator_epoch: i32,
96    pub transaction_version: i8,
97    pub unknown_tagged_fields: UnknownTaggedFields,
98}
99
100impl<'a> Default for WritableTxnMarker<'a> {
101    fn default() -> Self {
102        Self {
103            producer_id: 0i64,
104            producer_epoch: 0i16,
105            transaction_result: false,
106            topics: Vec::new(),
107            coordinator_epoch: 0i32,
108            transaction_version: 0i8,
109            unknown_tagged_fields: Default::default(),
110        }
111    }
112}
113
114impl<'a> WritableTxnMarker<'a> {
115    pub fn to_owned(&self) -> crate::owned::write_txn_markers_request::WritableTxnMarker {
116        crate::owned::write_txn_markers_request::WritableTxnMarker {
117            producer_id: (self.producer_id),
118            producer_epoch: (self.producer_epoch),
119            transaction_result: (self.transaction_result),
120            topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
121            coordinator_epoch: (self.coordinator_epoch),
122            transaction_version: (self.transaction_version),
123            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
124        }
125    }
126}
127
128impl<'a> Encode for WritableTxnMarker<'a> {
129    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
130        let flex = version >= 1;
131        if version >= 0 { put_i64(buf, self.producer_id) }
132        if version >= 0 { put_i16(buf, self.producer_epoch) }
133        if version >= 0 { put_bool(buf, self.transaction_result) }
134        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
135        if version >= 0 { put_i32(buf, self.coordinator_epoch) }
136        if version >= 2 { put_i8(buf, self.transaction_version) }
137        if flex {
138            let tagged = WriteTaggedFields::new();
139            tagged.write(buf, &self.unknown_tagged_fields);
140        }
141        Ok(())
142    }
143    fn encoded_len(&self, version: i16) -> usize {
144        let flex = version >= 1;
145        let mut n: usize = 0;
146        if version >= 0 { n += 8; }
147        if version >= 0 { n += 2; }
148        if version >= 0 { n += 1; }
149        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 }; }
150        if version >= 0 { n += 4; }
151        if version >= 2 { n += 1; }
152        if flex {
153            let known_pairs: Vec<(u32, usize)> = Vec::new();
154            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
155        }
156        n
157    }
158}
159
160impl<'de> DecodeBorrow<'de> for WritableTxnMarker<'de> {
161    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
162        let flex = version >= 1;
163        let mut out = Self::default();
164        if version >= 0 { out.producer_id = get_i64(buf)?; }
165        if version >= 0 { out.producer_epoch = get_i16(buf)?; }
166        if version >= 0 { out.transaction_result = get_bool(buf)?; }
167        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(WritableTxnMarkerTopic::decode_borrow(buf, version)?); } v }; }
168        if version >= 0 { out.coordinator_epoch = get_i32(buf)?; }
169        if version >= 2 { out.transaction_version = get_i8(buf)?; }
170        if flex {
171            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
172                Ok(false)
173            })?;
174        }
175        Ok(out)
176    }
177}
178
179#[derive(Debug, Clone, PartialEq, Eq)]
180pub struct WritableTxnMarkerTopic<'a> {
181    pub name: &'a str,
182    pub partition_indexes: Vec<i32>,
183    pub unknown_tagged_fields: UnknownTaggedFields,
184}
185
186impl<'a> Default for WritableTxnMarkerTopic<'a> {
187    fn default() -> Self {
188        Self {
189            name: "",
190            partition_indexes: Vec::new(),
191            unknown_tagged_fields: Default::default(),
192        }
193    }
194}
195
196impl<'a> WritableTxnMarkerTopic<'a> {
197    pub fn to_owned(&self) -> crate::owned::write_txn_markers_request::WritableTxnMarkerTopic {
198        crate::owned::write_txn_markers_request::WritableTxnMarkerTopic {
199            name: (self.name).to_string(),
200            partition_indexes: (self.partition_indexes).clone(),
201            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
202        }
203    }
204}
205
206impl<'a> Encode for WritableTxnMarkerTopic<'a> {
207    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
208        let flex = version >= 1;
209        if version >= 0 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
210        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex); for it in &self.partition_indexes { put_i32(buf, *it); } } }
211        if flex {
212            let tagged = WriteTaggedFields::new();
213            tagged.write(buf, &self.unknown_tagged_fields);
214        }
215        Ok(())
216    }
217    fn encoded_len(&self, version: i16) -> usize {
218        let flex = version >= 1;
219        let mut n: usize = 0;
220        if version >= 0 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
221        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partition_indexes).len(), flex); let body: usize = (self.partition_indexes).iter().map(|_| 4).sum(); prefix + body }; }
222        if flex {
223            let known_pairs: Vec<(u32, usize)> = Vec::new();
224            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
225        }
226        n
227    }
228}
229
230impl<'de> DecodeBorrow<'de> for WritableTxnMarkerTopic<'de> {
231    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
232        let flex = version >= 1;
233        let mut out = Self::default();
234        if version >= 0 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
235        if version >= 0 { out.partition_indexes = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
236        if flex {
237            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
238                Ok(false)
239            })?;
240        }
241        Ok(out)
242    }
243}