Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use 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 = 66;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 2;
13pub const FLEXIBLE_MIN: i16 = 0;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct ListTransactionsResponse<'a> {
20    pub throttle_time_ms: i32,
21    pub error_code: i16,
22    pub unknown_state_filters: Vec<&'a str>,
23    pub transaction_states: Vec<TransactionState<'a>>,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl ListTransactionsResponse<'_> {
27    pub fn to_owned(&self) -> crate::owned::list_transactions_response::ListTransactionsResponse {
28        crate::owned::list_transactions_response::ListTransactionsResponse {
29            throttle_time_ms: (self.throttle_time_ms),
30            error_code: (self.error_code),
31            unknown_state_filters: (self.unknown_state_filters)
32                .iter()
33                .map(std::string::ToString::to_string)
34                .collect(),
35            transaction_states: (self.transaction_states)
36                .iter()
37                .map(TransactionState::to_owned)
38                .collect(),
39            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
40        }
41    }
42}
43impl Encode for ListTransactionsResponse<'_> {
44    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
45        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
46            return Err(ProtocolError::UnsupportedVersion {
47                api_key: API_KEY,
48                version,
49            });
50        }
51        let flex = is_flexible(version);
52        if version >= 0 {
53            put_i32(buf, self.throttle_time_ms);
54        }
55        if version >= 0 {
56            put_i16(buf, self.error_code);
57        }
58        if version >= 0 {
59            {
60                crate::primitives::array::put_array_len(
61                    buf,
62                    (self.unknown_state_filters).len(),
63                    flex,
64                );
65                for it in &self.unknown_state_filters {
66                    if flex {
67                        put_compact_string(buf, it);
68                    } else {
69                        put_string(buf, it);
70                    }
71                }
72            }
73        }
74        if version >= 0 {
75            {
76                crate::primitives::array::put_array_len(buf, (self.transaction_states).len(), flex);
77                for it in &self.transaction_states {
78                    it.encode(buf, version)?;
79                }
80            }
81        }
82        if flex {
83            let tagged = WriteTaggedFields::new();
84            tagged.write(buf, &self.unknown_tagged_fields);
85        }
86        Ok(())
87    }
88    fn encoded_len(&self, version: i16) -> usize {
89        let flex = is_flexible(version);
90        let mut n: usize = 0;
91        if version >= 0 {
92            n += 4;
93        }
94        if version >= 0 {
95            n += 2;
96        }
97        if version >= 0 {
98            n += {
99                let prefix = crate::primitives::array::array_len_prefix_len(
100                    (self.unknown_state_filters).len(),
101                    flex,
102                );
103                let body: usize = (self.unknown_state_filters)
104                    .iter()
105                    .map(|it| {
106                        if flex {
107                            compact_string_len(it)
108                        } else {
109                            string_len(it)
110                        }
111                    })
112                    .sum();
113                prefix + body
114            };
115        }
116        if version >= 0 {
117            n += {
118                let prefix = crate::primitives::array::array_len_prefix_len(
119                    (self.transaction_states).len(),
120                    flex,
121                );
122                let body: usize = (self.transaction_states)
123                    .iter()
124                    .map(|it| it.encoded_len(version))
125                    .sum();
126                prefix + body
127            };
128        }
129        if flex {
130            let known_pairs: Vec<(u32, usize)> = Vec::new();
131            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
132        }
133        n
134    }
135}
136impl<'de> DecodeBorrow<'de> for ListTransactionsResponse<'de> {
137    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
138        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
139            return Err(ProtocolError::UnsupportedVersion {
140                api_key: API_KEY,
141                version,
142            });
143        }
144        let flex = is_flexible(version);
145        let mut out = Self::default();
146        if version >= 0 {
147            out.throttle_time_ms = get_i32(buf)?;
148        }
149        if version >= 0 {
150            out.error_code = get_i16(buf)?;
151        }
152        if version >= 0 {
153            out.unknown_state_filters = {
154                let n = crate::primitives::array::get_array_len(buf, flex)?;
155                let mut v = Vec::with_capacity(n);
156                for _ in 0..n {
157                    v.push(if flex {
158                        get_compact_string_borrowed(buf)?
159                    } else {
160                        get_string_borrowed(buf)?
161                    });
162                }
163                v
164            };
165        }
166        if version >= 0 {
167            out.transaction_states = {
168                let n = crate::primitives::array::get_array_len(buf, flex)?;
169                let mut v = Vec::with_capacity(n);
170                for _ in 0..n {
171                    v.push(TransactionState::decode_borrow(buf, version)?);
172                }
173                v
174            };
175        }
176        if flex {
177            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
178        }
179        Ok(out)
180    }
181}
182#[cfg(test)]
183impl ListTransactionsResponse<'_> {
184    #[must_use]
185    pub fn populated(version: i16) -> Self {
186        let mut m = Self::default();
187        if version >= 0 {
188            m.throttle_time_ms = 1i32;
189        }
190        if version >= 0 {
191            m.error_code = 1i16;
192        }
193        if version >= 0 {
194            m.unknown_state_filters = vec!["x"];
195        }
196        if version >= 0 {
197            m.transaction_states = vec![TransactionState::populated(version)];
198        }
199        m
200    }
201}
202#[derive(Debug, Clone, PartialEq, Eq, Default)]
203pub struct TransactionState<'a> {
204    pub transactional_id: &'a str,
205    pub producer_id: i64,
206    pub transaction_state: &'a str,
207    pub unknown_tagged_fields: UnknownTaggedFields,
208}
209impl TransactionState<'_> {
210    pub fn to_owned(&self) -> crate::owned::list_transactions_response::TransactionState {
211        crate::owned::list_transactions_response::TransactionState {
212            transactional_id: (self.transactional_id).to_string(),
213            producer_id: (self.producer_id),
214            transaction_state: (self.transaction_state).to_string(),
215            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
216        }
217    }
218}
219impl Encode for TransactionState<'_> {
220    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
221        let flex = version >= 0;
222        if version >= 0 {
223            if flex {
224                put_compact_string(buf, self.transactional_id);
225            } else {
226                put_string(buf, self.transactional_id);
227            }
228        }
229        if version >= 0 {
230            put_i64(buf, self.producer_id);
231        }
232        if version >= 0 {
233            if flex {
234                put_compact_string(buf, self.transaction_state);
235            } else {
236                put_string(buf, self.transaction_state);
237            }
238        }
239        if flex {
240            let tagged = WriteTaggedFields::new();
241            tagged.write(buf, &self.unknown_tagged_fields);
242        }
243        Ok(())
244    }
245    fn encoded_len(&self, version: i16) -> usize {
246        let flex = version >= 0;
247        let mut n: usize = 0;
248        if version >= 0 {
249            n += if flex {
250                compact_string_len(self.transactional_id)
251            } else {
252                string_len(self.transactional_id)
253            };
254        }
255        if version >= 0 {
256            n += 8;
257        }
258        if version >= 0 {
259            n += if flex {
260                compact_string_len(self.transaction_state)
261            } else {
262                string_len(self.transaction_state)
263            };
264        }
265        if flex {
266            let known_pairs: Vec<(u32, usize)> = Vec::new();
267            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
268        }
269        n
270    }
271}
272impl<'de> DecodeBorrow<'de> for TransactionState<'de> {
273    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
274        let flex = version >= 0;
275        let mut out = Self::default();
276        if version >= 0 {
277            out.transactional_id = if flex {
278                get_compact_string_borrowed(buf)?
279            } else {
280                get_string_borrowed(buf)?
281            };
282        }
283        if version >= 0 {
284            out.producer_id = get_i64(buf)?;
285        }
286        if version >= 0 {
287            out.transaction_state = if flex {
288                get_compact_string_borrowed(buf)?
289            } else {
290                get_string_borrowed(buf)?
291            };
292        }
293        if flex {
294            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
295        }
296        Ok(out)
297    }
298}
299#[cfg(test)]
300impl TransactionState<'_> {
301    #[must_use]
302    pub fn populated(version: i16) -> Self {
303        let mut m = Self::default();
304        if version >= 0 {
305            m.transactional_id = "x";
306        }
307        if version >= 0 {
308            m.producer_id = 1i64;
309        }
310        if version >= 0 {
311            m.transaction_state = "x";
312        }
313        m
314    }
315}