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