Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
WriteTxnMarkersRequest.owned.rs

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