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