crabka_protocol/opt/rustwide/workdir/generated/
DescribeTransactionsResponse.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 = 65;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
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 DescribeTransactionsResponse {
25 pub throttle_time_ms: i32,
26 pub transaction_states: Vec<TransactionState>,
27 pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl Encode for DescribeTransactionsResponse {
30 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
31 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
32 return Err(ProtocolError::UnsupportedVersion {
33 api_key: API_KEY,
34 version,
35 });
36 }
37 let flex = is_flexible(version);
38 if version >= 0 {
39 put_i32(buf, self.throttle_time_ms);
40 }
41 if version >= 0 {
42 {
43 crate::primitives::array::put_array_len(buf, (self.transaction_states).len(), flex);
44 for it in &self.transaction_states {
45 it.encode(buf, version)?;
46 }
47 }
48 }
49 if flex {
50 let tagged = WriteTaggedFields::new();
51 tagged.write(buf, &self.unknown_tagged_fields);
52 }
53 Ok(())
54 }
55 fn encoded_len(&self, version: i16) -> usize {
56 let flex = is_flexible(version);
57 let mut n: usize = 0;
58 if version >= 0 {
59 n += 4;
60 }
61 if version >= 0 {
62 n += {
63 let prefix = crate::primitives::array::array_len_prefix_len(
64 (self.transaction_states).len(),
65 flex,
66 );
67 let body: usize = (self.transaction_states)
68 .iter()
69 .map(|it| it.encoded_len(version))
70 .sum();
71 prefix + body
72 };
73 }
74 if flex {
75 let known_pairs: Vec<(u32, usize)> = Vec::new();
76 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
77 }
78 n
79 }
80}
81impl Decode<'_> for DescribeTransactionsResponse {
82 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
83 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
84 return Err(ProtocolError::UnsupportedVersion {
85 api_key: API_KEY,
86 version,
87 });
88 }
89 let flex = is_flexible(version);
90 let mut out = Self::default();
91 if version >= 0 {
92 out.throttle_time_ms = get_i32(buf)?;
93 }
94 if version >= 0 {
95 out.transaction_states = {
96 let n = crate::primitives::array::get_array_len(buf, flex)?;
97 let mut v = Vec::with_capacity(n);
98 for _ in 0..n {
99 v.push(TransactionState::decode(buf, version)?);
100 }
101 v
102 };
103 }
104 if flex {
105 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
106 }
107 Ok(out)
108 }
109}
110#[cfg(test)]
111impl DescribeTransactionsResponse {
112 #[must_use]
113 pub fn populated(version: i16) -> Self {
114 let mut m = Self::default();
115 if version >= 0 {
116 m.throttle_time_ms = 1i32;
117 }
118 if version >= 0 {
119 m.transaction_states = vec![TransactionState::populated(version)];
120 }
121 m
122 }
123}
124#[derive(Debug, Clone, PartialEq, Eq, Default)]
125pub struct TransactionState {
126 pub error_code: i16,
127 pub transactional_id: String,
128 pub transaction_state: String,
129 pub transaction_timeout_ms: i32,
130 pub transaction_start_time_ms: i64,
131 pub producer_id: i64,
132 pub producer_epoch: i16,
133 pub topics: Vec<TopicData>,
134 pub unknown_tagged_fields: UnknownTaggedFields,
135}
136impl Encode for TransactionState {
137 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
138 let flex = version >= 0;
139 if version >= 0 {
140 put_i16(buf, self.error_code);
141 }
142 if version >= 0 {
143 if flex {
144 put_compact_string(buf, &self.transactional_id);
145 } else {
146 put_string(buf, &self.transactional_id);
147 }
148 }
149 if version >= 0 {
150 if flex {
151 put_compact_string(buf, &self.transaction_state);
152 } else {
153 put_string(buf, &self.transaction_state);
154 }
155 }
156 if version >= 0 {
157 put_i32(buf, self.transaction_timeout_ms);
158 }
159 if version >= 0 {
160 put_i64(buf, self.transaction_start_time_ms);
161 }
162 if version >= 0 {
163 put_i64(buf, self.producer_id);
164 }
165 if version >= 0 {
166 put_i16(buf, self.producer_epoch);
167 }
168 if version >= 0 {
169 {
170 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
171 for it in &self.topics {
172 it.encode(buf, version)?;
173 }
174 }
175 }
176 if flex {
177 let tagged = WriteTaggedFields::new();
178 tagged.write(buf, &self.unknown_tagged_fields);
179 }
180 Ok(())
181 }
182 fn encoded_len(&self, version: i16) -> usize {
183 let flex = version >= 0;
184 let mut n: usize = 0;
185 if version >= 0 {
186 n += 2;
187 }
188 if version >= 0 {
189 n += if flex {
190 compact_string_len(&self.transactional_id)
191 } else {
192 string_len(&self.transactional_id)
193 };
194 }
195 if version >= 0 {
196 n += if flex {
197 compact_string_len(&self.transaction_state)
198 } else {
199 string_len(&self.transaction_state)
200 };
201 }
202 if version >= 0 {
203 n += 4;
204 }
205 if version >= 0 {
206 n += 8;
207 }
208 if version >= 0 {
209 n += 8;
210 }
211 if version >= 0 {
212 n += 2;
213 }
214 if version >= 0 {
215 n += {
216 let prefix =
217 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
218 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
219 prefix + body
220 };
221 }
222 if flex {
223 let known_pairs: Vec<(u32, usize)> = Vec::new();
224 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
225 }
226 n
227 }
228}
229impl Decode<'_> for TransactionState {
230 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
231 let flex = version >= 0;
232 let mut out = Self::default();
233 if version >= 0 {
234 out.error_code = get_i16(buf)?;
235 }
236 if version >= 0 {
237 out.transactional_id = if flex {
238 get_compact_string_owned(buf)?
239 } else {
240 get_string_owned(buf)?
241 };
242 }
243 if version >= 0 {
244 out.transaction_state = if flex {
245 get_compact_string_owned(buf)?
246 } else {
247 get_string_owned(buf)?
248 };
249 }
250 if version >= 0 {
251 out.transaction_timeout_ms = get_i32(buf)?;
252 }
253 if version >= 0 {
254 out.transaction_start_time_ms = get_i64(buf)?;
255 }
256 if version >= 0 {
257 out.producer_id = get_i64(buf)?;
258 }
259 if version >= 0 {
260 out.producer_epoch = get_i16(buf)?;
261 }
262 if version >= 0 {
263 out.topics = {
264 let n = crate::primitives::array::get_array_len(buf, flex)?;
265 let mut v = Vec::with_capacity(n);
266 for _ in 0..n {
267 v.push(TopicData::decode(buf, version)?);
268 }
269 v
270 };
271 }
272 if flex {
273 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
274 }
275 Ok(out)
276 }
277}
278#[cfg(test)]
279impl TransactionState {
280 #[must_use]
281 pub fn populated(version: i16) -> Self {
282 let mut m = Self::default();
283 if version >= 0 {
284 m.error_code = 1i16;
285 }
286 if version >= 0 {
287 m.transactional_id = "x".to_string();
288 }
289 if version >= 0 {
290 m.transaction_state = "x".to_string();
291 }
292 if version >= 0 {
293 m.transaction_timeout_ms = 1i32;
294 }
295 if version >= 0 {
296 m.transaction_start_time_ms = 1i64;
297 }
298 if version >= 0 {
299 m.producer_id = 1i64;
300 }
301 if version >= 0 {
302 m.producer_epoch = 1i16;
303 }
304 if version >= 0 {
305 m.topics = vec![TopicData::populated(version)];
306 }
307 m
308 }
309}
310#[derive(Debug, Clone, PartialEq, Eq, Default)]
311pub struct TopicData {
312 pub topic: String,
313 pub partitions: Vec<i32>,
314 pub unknown_tagged_fields: UnknownTaggedFields,
315}
316impl Encode for TopicData {
317 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
318 let flex = version >= 0;
319 if version >= 0 {
320 if flex {
321 put_compact_string(buf, &self.topic);
322 } else {
323 put_string(buf, &self.topic);
324 }
325 }
326 if version >= 0 {
327 {
328 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
329 for it in &self.partitions {
330 put_i32(buf, *it);
331 }
332 }
333 }
334 if flex {
335 let tagged = WriteTaggedFields::new();
336 tagged.write(buf, &self.unknown_tagged_fields);
337 }
338 Ok(())
339 }
340 fn encoded_len(&self, version: i16) -> usize {
341 let flex = version >= 0;
342 let mut n: usize = 0;
343 if version >= 0 {
344 n += if flex {
345 compact_string_len(&self.topic)
346 } else {
347 string_len(&self.topic)
348 };
349 }
350 if version >= 0 {
351 n += {
352 let prefix =
353 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
354 let body: usize = (self.partitions).iter().map(|_| 4).sum();
355 prefix + body
356 };
357 }
358 if flex {
359 let known_pairs: Vec<(u32, usize)> = Vec::new();
360 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
361 }
362 n
363 }
364}
365impl Decode<'_> for TopicData {
366 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
367 let flex = version >= 0;
368 let mut out = Self::default();
369 if version >= 0 {
370 out.topic = if flex {
371 get_compact_string_owned(buf)?
372 } else {
373 get_string_owned(buf)?
374 };
375 }
376 if version >= 0 {
377 out.partitions = {
378 let n = crate::primitives::array::get_array_len(buf, flex)?;
379 let mut v = Vec::with_capacity(n);
380 for _ in 0..n {
381 v.push(get_i32(buf)?);
382 }
383 v
384 };
385 }
386 if flex {
387 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
388 }
389 Ok(out)
390 }
391}
392#[cfg(test)]
393impl TopicData {
394 #[must_use]
395 pub fn populated(version: i16) -> Self {
396 let mut m = Self::default();
397 if version >= 0 {
398 m.topic = "x".to_string();
399 }
400 if version >= 0 {
401 m.partitions = vec![1i32];
402 }
403 m
404 }
405}
406
407#[must_use]
410#[allow(unused_comparisons)]
411pub fn default_json(version: i16) -> ::serde_json::Value {
412 let mut obj = ::serde_json::Map::new();
413 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
414 obj.insert(
415 "transactionStates".to_string(),
416 ::serde_json::Value::Array(vec![]),
417 );
418 ::serde_json::Value::Object(obj)
419}