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