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