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