Skip to main content

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

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