Skip to main content

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

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