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