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::{get_bool, get_i16, get_i32, get_i64, get_i8, put_bool, put_i16, put_i32, put_i64, put_i8};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned,
8    put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
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
18#[inline]
19fn is_flexible(version: i16) -> bool { 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}
26
27impl Encode for WriteTxnMarkersRequest {
28    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
29        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
30            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
31        }
32        let flex = is_flexible(version);
33        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.markers).len(), flex); for it in &self.markers { it.encode(buf, version)?; } } }
34        if flex {
35            let tagged = WriteTaggedFields::new();
36            tagged.write(buf, &self.unknown_tagged_fields);
37        }
38        Ok(())
39    }
40    fn encoded_len(&self, version: i16) -> usize {
41        let flex = is_flexible(version);
42        let mut n: usize = 0;
43        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.markers).len(), flex); let body: usize = (self.markers).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
44        if flex {
45            let known_pairs: Vec<(u32, usize)> = Vec::new();
46            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
47        }
48        n
49    }
50}
51
52impl<'de> Decode<'de> for WriteTxnMarkersRequest {
53    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
54        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
55            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
56        }
57        let flex = is_flexible(version);
58        let mut out = Self::default();
59        if version >= 0 { out.markers = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(WritableTxnMarker::decode(buf, version)?); } v }; }
60        if flex {
61            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
62                Ok(false)
63            })?;
64        }
65        Ok(out)
66    }
67}
68
69#[derive(Debug, Clone, PartialEq, Eq, Default)]
70pub struct WritableTxnMarker {
71    pub producer_id: i64,
72    pub producer_epoch: i16,
73    pub transaction_result: bool,
74    pub topics: Vec<WritableTxnMarkerTopic>,
75    pub coordinator_epoch: i32,
76    pub transaction_version: i8,
77    pub unknown_tagged_fields: UnknownTaggedFields,
78}
79
80impl Encode for WritableTxnMarker {
81    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
82        let flex = version >= 1;
83        if version >= 0 { put_i64(buf, self.producer_id) }
84        if version >= 0 { put_i16(buf, self.producer_epoch) }
85        if version >= 0 { put_bool(buf, self.transaction_result) }
86        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
87        if version >= 0 { put_i32(buf, self.coordinator_epoch) }
88        if version >= 2 { put_i8(buf, self.transaction_version) }
89        if flex {
90            let tagged = WriteTaggedFields::new();
91            tagged.write(buf, &self.unknown_tagged_fields);
92        }
93        Ok(())
94    }
95    fn encoded_len(&self, version: i16) -> usize {
96        let flex = version >= 1;
97        let mut n: usize = 0;
98        if version >= 0 { n += 8; }
99        if version >= 0 { n += 2; }
100        if version >= 0 { n += 1; }
101        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
102        if version >= 0 { n += 4; }
103        if version >= 2 { n += 1; }
104        if flex {
105            let known_pairs: Vec<(u32, usize)> = Vec::new();
106            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
107        }
108        n
109    }
110}
111
112impl<'de> Decode<'de> for WritableTxnMarker {
113    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
114        let flex = version >= 1;
115        let mut out = Self::default();
116        if version >= 0 { out.producer_id = get_i64(buf)?; }
117        if version >= 0 { out.producer_epoch = get_i16(buf)?; }
118        if version >= 0 { out.transaction_result = get_bool(buf)?; }
119        if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(WritableTxnMarkerTopic::decode(buf, version)?); } v }; }
120        if version >= 0 { out.coordinator_epoch = get_i32(buf)?; }
121        if version >= 2 { out.transaction_version = get_i8(buf)?; }
122        if flex {
123            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
124                Ok(false)
125            })?;
126        }
127        Ok(out)
128    }
129}
130
131#[derive(Debug, Clone, PartialEq, Eq, Default)]
132pub struct WritableTxnMarkerTopic {
133    pub name: String,
134    pub partition_indexes: Vec<i32>,
135    pub unknown_tagged_fields: UnknownTaggedFields,
136}
137
138impl Encode for WritableTxnMarkerTopic {
139    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
140        let flex = version >= 1;
141        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
142        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex); for it in &self.partition_indexes { put_i32(buf, *it); } } }
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 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
153        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partition_indexes).len(), flex); let body: usize = (self.partition_indexes).iter().map(|_| 4).sum(); prefix + body }; }
154        if flex {
155            let known_pairs: Vec<(u32, usize)> = Vec::new();
156            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
157        }
158        n
159    }
160}
161
162impl<'de> Decode<'de> for WritableTxnMarkerTopic {
163    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
164        let flex = version >= 1;
165        let mut out = Self::default();
166        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
167        if version >= 0 { out.partition_indexes = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
168        if flex {
169            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
170                Ok(false)
171            })?;
172        }
173        Ok(out)
174    }
175}
176
177/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
178/// Only includes fields valid for the given version.
179#[must_use]
180#[allow(unused_comparisons)]
181pub fn default_json(version: i16) -> ::serde_json::Value {
182    let mut obj = ::serde_json::Map::new();
183    obj.insert("markers".to_string(), ::serde_json::Value::Array(vec![]));
184    ::serde_json::Value::Object(obj)
185}
186
187impl crate::ProtocolRequest for WriteTxnMarkersRequest {
188    const API_KEY: i16 = API_KEY;
189    const MIN_VERSION: i16 = MIN_VERSION;
190    const MAX_VERSION: i16 = MAX_VERSION;
191    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
192    type Response = super::write_txn_markers_response::WriteTxnMarkersResponse;
193}