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