crabka_protocol/opt/rustwide/workdir/generated/
WriteTxnMarkersResponse.borrowed.rs1use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
3use crate::primitives::string_bytes::{
4 compact_string_len, put_compact_string, put_string, string_len,
5};
6use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
7use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
8use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
9use bytes::BufMut;
10pub const API_KEY: i16 = 27;
11pub const MIN_VERSION: i16 = 1;
12pub const MAX_VERSION: i16 = 2;
13pub const FLEXIBLE_MIN: i16 = 1;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16 version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct WriteTxnMarkersResponse<'a> {
20 pub markers: Vec<WritableTxnMarkerResult<'a>>,
21 pub unknown_tagged_fields: UnknownTaggedFields,
22}
23impl WriteTxnMarkersResponse<'_> {
24 pub fn to_owned(&self) -> crate::owned::write_txn_markers_response::WriteTxnMarkersResponse {
25 crate::owned::write_txn_markers_response::WriteTxnMarkersResponse {
26 markers: (self.markers)
27 .iter()
28 .map(WritableTxnMarkerResult::to_owned)
29 .collect(),
30 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
31 }
32 }
33}
34impl Encode for WriteTxnMarkersResponse<'_> {
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<'de> DecodeBorrow<'de> for WriteTxnMarkersResponse<'de> {
79 fn decode_borrow(buf: &mut &'de [u8], 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(WritableTxnMarkerResult::decode_borrow(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 WriteTxnMarkersResponse<'_> {
106 #[must_use]
107 pub fn populated(version: i16) -> Self {
108 let mut m = Self::default();
109 if version >= 0 {
110 m.markers = vec![WritableTxnMarkerResult::populated(version)];
111 }
112 m
113 }
114}
115#[derive(Debug, Clone, PartialEq, Eq, Default)]
116pub struct WritableTxnMarkerResult<'a> {
117 pub producer_id: i64,
118 pub topics: Vec<WritableTxnMarkerTopicResult<'a>>,
119 pub unknown_tagged_fields: UnknownTaggedFields,
120}
121impl WritableTxnMarkerResult<'_> {
122 pub fn to_owned(&self) -> crate::owned::write_txn_markers_response::WritableTxnMarkerResult {
123 crate::owned::write_txn_markers_response::WritableTxnMarkerResult {
124 producer_id: (self.producer_id),
125 topics: (self.topics)
126 .iter()
127 .map(WritableTxnMarkerTopicResult::to_owned)
128 .collect(),
129 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
130 }
131 }
132}
133impl Encode for WritableTxnMarkerResult<'_> {
134 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
135 let flex = version >= 1;
136 if version >= 0 {
137 put_i64(buf, self.producer_id);
138 }
139 if version >= 0 {
140 {
141 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
142 for it in &self.topics {
143 it.encode(buf, version)?;
144 }
145 }
146 }
147 if flex {
148 let tagged = WriteTaggedFields::new();
149 tagged.write(buf, &self.unknown_tagged_fields);
150 }
151 Ok(())
152 }
153 fn encoded_len(&self, version: i16) -> usize {
154 let flex = version >= 1;
155 let mut n: usize = 0;
156 if version >= 0 {
157 n += 8;
158 }
159 if version >= 0 {
160 n += {
161 let prefix =
162 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
163 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
164 prefix + body
165 };
166 }
167 if flex {
168 let known_pairs: Vec<(u32, usize)> = Vec::new();
169 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
170 }
171 n
172 }
173}
174impl<'de> DecodeBorrow<'de> for WritableTxnMarkerResult<'de> {
175 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
176 let flex = version >= 1;
177 let mut out = Self::default();
178 if version >= 0 {
179 out.producer_id = get_i64(buf)?;
180 }
181 if version >= 0 {
182 out.topics = {
183 let n = crate::primitives::array::get_array_len(buf, flex)?;
184 let mut v = Vec::with_capacity(n);
185 for _ in 0..n {
186 v.push(WritableTxnMarkerTopicResult::decode_borrow(buf, version)?);
187 }
188 v
189 };
190 }
191 if flex {
192 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
193 }
194 Ok(out)
195 }
196}
197#[cfg(test)]
198impl WritableTxnMarkerResult<'_> {
199 #[must_use]
200 pub fn populated(version: i16) -> Self {
201 let mut m = Self::default();
202 if version >= 0 {
203 m.producer_id = 1i64;
204 }
205 if version >= 0 {
206 m.topics = vec![WritableTxnMarkerTopicResult::populated(version)];
207 }
208 m
209 }
210}
211#[derive(Debug, Clone, PartialEq, Eq, Default)]
212pub struct WritableTxnMarkerTopicResult<'a> {
213 pub name: &'a str,
214 pub partitions: Vec<WritableTxnMarkerPartitionResult>,
215 pub unknown_tagged_fields: UnknownTaggedFields,
216}
217impl WritableTxnMarkerTopicResult<'_> {
218 pub fn to_owned(
219 &self,
220 ) -> crate::owned::write_txn_markers_response::WritableTxnMarkerTopicResult {
221 crate::owned::write_txn_markers_response::WritableTxnMarkerTopicResult {
222 name: (self.name).to_string(),
223 partitions: (self.partitions)
224 .iter()
225 .map(WritableTxnMarkerPartitionResult::to_owned)
226 .collect(),
227 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
228 }
229 }
230}
231impl Encode for WritableTxnMarkerTopicResult<'_> {
232 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
233 let flex = version >= 1;
234 if version >= 0 {
235 if flex {
236 put_compact_string(buf, self.name);
237 } else {
238 put_string(buf, self.name);
239 }
240 }
241 if version >= 0 {
242 {
243 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
244 for it in &self.partitions {
245 it.encode(buf, version)?;
246 }
247 }
248 }
249 if flex {
250 let tagged = WriteTaggedFields::new();
251 tagged.write(buf, &self.unknown_tagged_fields);
252 }
253 Ok(())
254 }
255 fn encoded_len(&self, version: i16) -> usize {
256 let flex = version >= 1;
257 let mut n: usize = 0;
258 if version >= 0 {
259 n += if flex {
260 compact_string_len(self.name)
261 } else {
262 string_len(self.name)
263 };
264 }
265 if version >= 0 {
266 n += {
267 let prefix =
268 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
269 let body: usize = (self.partitions)
270 .iter()
271 .map(|it| it.encoded_len(version))
272 .sum();
273 prefix + body
274 };
275 }
276 if flex {
277 let known_pairs: Vec<(u32, usize)> = Vec::new();
278 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
279 }
280 n
281 }
282}
283impl<'de> DecodeBorrow<'de> for WritableTxnMarkerTopicResult<'de> {
284 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
285 let flex = version >= 1;
286 let mut out = Self::default();
287 if version >= 0 {
288 out.name = if flex {
289 get_compact_string_borrowed(buf)?
290 } else {
291 get_string_borrowed(buf)?
292 };
293 }
294 if version >= 0 {
295 out.partitions = {
296 let n = crate::primitives::array::get_array_len(buf, flex)?;
297 let mut v = Vec::with_capacity(n);
298 for _ in 0..n {
299 v.push(WritableTxnMarkerPartitionResult::decode_borrow(
300 buf, version,
301 )?);
302 }
303 v
304 };
305 }
306 if flex {
307 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
308 }
309 Ok(out)
310 }
311}
312#[cfg(test)]
313impl WritableTxnMarkerTopicResult<'_> {
314 #[must_use]
315 pub fn populated(version: i16) -> Self {
316 let mut m = Self::default();
317 if version >= 0 {
318 m.name = "x";
319 }
320 if version >= 0 {
321 m.partitions = vec![WritableTxnMarkerPartitionResult::populated(version)];
322 }
323 m
324 }
325}
326#[derive(Debug, Clone, PartialEq, Eq, Default)]
327pub struct WritableTxnMarkerPartitionResult {
328 pub partition_index: i32,
329 pub error_code: i16,
330 pub unknown_tagged_fields: UnknownTaggedFields,
331}
332impl WritableTxnMarkerPartitionResult {
333 pub fn to_owned(
334 &self,
335 ) -> crate::owned::write_txn_markers_response::WritableTxnMarkerPartitionResult {
336 crate::owned::write_txn_markers_response::WritableTxnMarkerPartitionResult {
337 partition_index: (self.partition_index),
338 error_code: (self.error_code),
339 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
340 }
341 }
342}
343impl Encode for WritableTxnMarkerPartitionResult {
344 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
345 let flex = version >= 1;
346 if version >= 0 {
347 put_i32(buf, self.partition_index);
348 }
349 if version >= 0 {
350 put_i16(buf, self.error_code);
351 }
352 if flex {
353 let tagged = WriteTaggedFields::new();
354 tagged.write(buf, &self.unknown_tagged_fields);
355 }
356 Ok(())
357 }
358 fn encoded_len(&self, version: i16) -> usize {
359 let flex = version >= 1;
360 let mut n: usize = 0;
361 if version >= 0 {
362 n += 4;
363 }
364 if version >= 0 {
365 n += 2;
366 }
367 if flex {
368 let known_pairs: Vec<(u32, usize)> = Vec::new();
369 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
370 }
371 n
372 }
373}
374impl<'de> DecodeBorrow<'de> for WritableTxnMarkerPartitionResult {
375 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
376 let flex = version >= 1;
377 let mut out = Self::default();
378 if version >= 0 {
379 out.partition_index = get_i32(buf)?;
380 }
381 if version >= 0 {
382 out.error_code = get_i16(buf)?;
383 }
384 if flex {
385 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
386 }
387 Ok(out)
388 }
389}
390#[cfg(test)]
391impl WritableTxnMarkerPartitionResult {
392 #[must_use]
393 pub fn populated(version: i16) -> Self {
394 let mut m = Self::default();
395 if version >= 0 {
396 m.partition_index = 1i32;
397 }
398 if version >= 0 {
399 m.error_code = 1i16;
400 }
401 m
402 }
403}