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