Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeTransactionsResponse.owned.rs

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