Skip to main content

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

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