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