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