Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
WriteTxnMarkersResponse.borrowed.rs

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