Skip to main content

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

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