Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
WriteTxnMarkersRequest.borrowed.rs

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