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        fixed::{
9            get_bool, get_i8, get_i16, get_i32, get_i64, put_bool, put_i8, put_i16, put_i32,
10            put_i64,
11        },
12        string_bytes::{
13            compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
14            put_string, string_len,
15        },
16    },
17    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 27;
20pub const MIN_VERSION: i16 = 1;
21pub const MAX_VERSION: i16 = 2;
22pub const LATEST_STABLE_VERSION: i16 = 2;
23pub const FLEXIBLE_MIN: i16 = 1;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27    version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq, Default)]
30pub struct WriteTxnMarkersRequest {
31    pub markers: Vec<WritableTxnMarker>,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for WriteTxnMarkersRequest {
35    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37            return Err(ProtocolError::UnsupportedVersion {
38                api_key: API_KEY,
39                version,
40            });
41        }
42        let flex = is_flexible(version);
43        if version >= 0 {
44            {
45                crate::primitives::array::put_array_len(buf, (self.markers).len(), flex);
46                for it in &self.markers {
47                    it.encode(buf, version)?;
48                }
49            };
50        }
51        if flex {
52            let tagged = WriteTaggedFields::new();
53            tagged.write(buf, &self.unknown_tagged_fields);
54        }
55        Ok(())
56    }
57    fn encoded_len(&self, version: i16) -> usize {
58        let flex = is_flexible(version);
59        let mut n: usize = 0;
60        if version >= 0 {
61            n += {
62                let prefix =
63                    crate::primitives::array::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 = crate::primitives::array::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                crate::primitives::array::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 =
172                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
173                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
174                prefix + body
175            };
176        }
177        if version >= 0 {
178            n += 4;
179        }
180        if version >= 2 {
181            n += 1;
182        }
183        if flex {
184            let known_pairs: Vec<(u32, usize)> = Vec::new();
185            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
186        }
187        n
188    }
189}
190impl Decode<'_> for WritableTxnMarker {
191    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
192        let flex = version >= 1;
193        let mut out = Self::default();
194        if version >= 0 {
195            out.producer_id = get_i64(buf)?;
196        }
197        if version >= 0 {
198            out.producer_epoch = get_i16(buf)?;
199        }
200        if version >= 0 {
201            out.transaction_result = get_bool(buf)?;
202        }
203        if version >= 0 {
204            out.topics = {
205                let n = crate::primitives::array::get_array_len(buf, flex)?;
206                let mut v = Vec::with_capacity(n);
207                for _ in 0..n {
208                    v.push(WritableTxnMarkerTopic::decode(buf, version)?);
209                }
210                v
211            };
212        }
213        if version >= 0 {
214            out.coordinator_epoch = get_i32(buf)?;
215        }
216        if version >= 2 {
217            out.transaction_version = get_i8(buf)?;
218        }
219        if flex {
220            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
221        }
222        Ok(out)
223    }
224}
225#[cfg(test)]
226impl WritableTxnMarker {
227    #[must_use]
228    pub fn populated(version: i16) -> Self {
229        let mut m = Self::default();
230        if version >= 0 {
231            m.producer_id = 1i64;
232        }
233        if version >= 0 {
234            m.producer_epoch = 1i16;
235        }
236        if version >= 0 {
237            m.transaction_result = true;
238        }
239        if version >= 0 {
240            m.topics = vec![WritableTxnMarkerTopic::populated(version)];
241        }
242        if version >= 0 {
243            m.coordinator_epoch = 1i32;
244        }
245        if version >= 2 {
246            m.transaction_version = 1i8;
247        }
248        m
249    }
250}
251#[derive(Debug, Clone, PartialEq, Eq, Default)]
252pub struct WritableTxnMarkerTopic {
253    pub name: String,
254    pub partition_indexes: Vec<i32>,
255    pub unknown_tagged_fields: UnknownTaggedFields,
256}
257impl Encode for WritableTxnMarkerTopic {
258    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
259        let flex = version >= 1;
260        if version >= 0 {
261            if flex {
262                let () = put_compact_string(buf, &self.name);
263            } else {
264                let () = put_string(buf, &self.name);
265            }
266        }
267        if version >= 0 {
268            {
269                crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex);
270                for it in &self.partition_indexes {
271                    put_i32(buf, *it);
272                }
273            };
274        }
275        if flex {
276            let tagged = WriteTaggedFields::new();
277            tagged.write(buf, &self.unknown_tagged_fields);
278        }
279        Ok(())
280    }
281    fn encoded_len(&self, version: i16) -> usize {
282        let flex = version >= 1;
283        let mut n: usize = 0;
284        if version >= 0 {
285            n += if flex {
286                compact_string_len(&self.name)
287            } else {
288                string_len(&self.name)
289            };
290        }
291        if version >= 0 {
292            n += {
293                let prefix = crate::primitives::array::array_len_prefix_len(
294                    (self.partition_indexes).len(),
295                    flex,
296                );
297                let body: usize = (self.partition_indexes).iter().map(|_| 4).sum();
298                prefix + body
299            };
300        }
301        if flex {
302            let known_pairs: Vec<(u32, usize)> = Vec::new();
303            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
304        }
305        n
306    }
307}
308impl Decode<'_> for WritableTxnMarkerTopic {
309    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
310        let flex = version >= 1;
311        let mut out = Self::default();
312        if version >= 0 {
313            out.name = if flex {
314                get_compact_string_owned(buf)?
315            } else {
316                get_string_owned(buf)?
317            };
318        }
319        if version >= 0 {
320            out.partition_indexes = {
321                let n = crate::primitives::array::get_array_len(buf, flex)?;
322                let mut v = Vec::with_capacity(n);
323                for _ in 0..n {
324                    v.push(get_i32(buf)?);
325                }
326                v
327            };
328        }
329        if flex {
330            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
331        }
332        Ok(out)
333    }
334}
335#[cfg(test)]
336impl WritableTxnMarkerTopic {
337    #[must_use]
338    pub fn populated(version: i16) -> Self {
339        let mut m = Self::default();
340        if version >= 0 {
341            m.name = "x".to_string();
342        }
343        if version >= 0 {
344            m.partition_indexes = vec![1i32];
345        }
346        m
347    }
348}
349/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
350/// Only includes fields valid for the given version.
351#[must_use]
352#[allow(unused_comparisons)]
353pub fn default_json(_version: i16) -> ::serde_json::Value {
354    let mut obj = ::serde_json::Map::new();
355    obj.insert("markers".to_string(), ::serde_json::Value::Array(vec![]));
356    ::serde_json::Value::Object(obj)
357}
358impl crate::ProtocolRequest for WriteTxnMarkersRequest {
359    const API_KEY: i16 = API_KEY;
360    const MIN_VERSION: i16 = MIN_VERSION;
361    const MAX_VERSION: i16 = MAX_VERSION;
362    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
363    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
364    type Response = super::write_txn_markers_response::WriteTxnMarkersResponse;
365}