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