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::{
10    get_compact_string_borrowed, get_string_borrowed,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 65;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 0;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct DescribeTransactionsResponse<'a> {
25    pub throttle_time_ms: i32,
26    pub transaction_states: Vec<TransactionState<'a>>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl<'a> Default for DescribeTransactionsResponse<'a> {
31    fn default() -> Self {
32        Self {
33            throttle_time_ms: 0i32,
34            transaction_states: Vec::new(),
35            unknown_tagged_fields: Default::default(),
36        }
37    }
38}
39
40impl<'a> DescribeTransactionsResponse<'a> {
41    pub fn to_owned(&self) -> crate::owned::describe_transactions_response::DescribeTransactionsResponse {
42        crate::owned::describe_transactions_response::DescribeTransactionsResponse {
43            throttle_time_ms: (self.throttle_time_ms),
44            transaction_states: (self.transaction_states).iter().map(|it| it.to_owned()).collect(),
45            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
46        }
47    }
48}
49
50impl<'a> Encode for DescribeTransactionsResponse<'a> {
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 { api_key: API_KEY, version });
54        }
55        let flex = is_flexible(version);
56        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
57        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.transaction_states).len(), flex); for it in &self.transaction_states { it.encode(buf, version)?; } } }
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 { n += 4; }
68        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.transaction_states).len(), flex); let body: usize = (self.transaction_states).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
69        if flex {
70            let known_pairs: Vec<(u32, usize)> = Vec::new();
71            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
72        }
73        n
74    }
75}
76
77impl<'de> DecodeBorrow<'de> for DescribeTransactionsResponse<'de> {
78    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
79        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
81        }
82        let flex = is_flexible(version);
83        let mut out = Self::default();
84        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
85        if version >= 0 { out.transaction_states = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TransactionState::decode_borrow(buf, version)?); } v }; }
86        if flex {
87            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
88                Ok(false)
89            })?;
90        }
91        Ok(out)
92    }
93}
94
95#[derive(Debug, Clone, PartialEq, Eq)]
96pub struct TransactionState<'a> {
97    pub error_code: i16,
98    pub transactional_id: &'a str,
99    pub transaction_state: &'a str,
100    pub transaction_timeout_ms: i32,
101    pub transaction_start_time_ms: i64,
102    pub producer_id: i64,
103    pub producer_epoch: i16,
104    pub topics: Vec<TopicData<'a>>,
105    pub unknown_tagged_fields: UnknownTaggedFields,
106}
107
108impl<'a> Default for TransactionState<'a> {
109    fn default() -> Self {
110        Self {
111            error_code: 0i16,
112            transactional_id: "",
113            transaction_state: "",
114            transaction_timeout_ms: 0i32,
115            transaction_start_time_ms: 0i64,
116            producer_id: 0i64,
117            producer_epoch: 0i16,
118            topics: Vec::new(),
119            unknown_tagged_fields: Default::default(),
120        }
121    }
122}
123
124impl<'a> TransactionState<'a> {
125    pub fn to_owned(&self) -> crate::owned::describe_transactions_response::TransactionState {
126        crate::owned::describe_transactions_response::TransactionState {
127            error_code: (self.error_code),
128            transactional_id: (self.transactional_id).to_string(),
129            transaction_state: (self.transaction_state).to_string(),
130            transaction_timeout_ms: (self.transaction_timeout_ms),
131            transaction_start_time_ms: (self.transaction_start_time_ms),
132            producer_id: (self.producer_id),
133            producer_epoch: (self.producer_epoch),
134            topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
135            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
136        }
137    }
138}
139
140impl<'a> Encode for TransactionState<'a> {
141    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
142        let flex = version >= 0;
143        if version >= 0 { put_i16(buf, self.error_code) }
144        if version >= 0 { if flex { put_compact_string(buf, self.transactional_id) } else { put_string(buf, self.transactional_id) } }
145        if version >= 0 { if flex { put_compact_string(buf, self.transaction_state) } else { put_string(buf, self.transaction_state) } }
146        if version >= 0 { put_i32(buf, self.transaction_timeout_ms) }
147        if version >= 0 { put_i64(buf, self.transaction_start_time_ms) }
148        if version >= 0 { put_i64(buf, self.producer_id) }
149        if version >= 0 { put_i16(buf, self.producer_epoch) }
150        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
151        if flex {
152            let tagged = WriteTaggedFields::new();
153            tagged.write(buf, &self.unknown_tagged_fields);
154        }
155        Ok(())
156    }
157    fn encoded_len(&self, version: i16) -> usize {
158        let flex = version >= 0;
159        let mut n: usize = 0;
160        if version >= 0 { n += 2; }
161        if version >= 0 { n += if flex { compact_string_len(self.transactional_id) } else { string_len(self.transactional_id) }; }
162        if version >= 0 { n += if flex { compact_string_len(self.transaction_state) } else { string_len(self.transaction_state) }; }
163        if version >= 0 { n += 4; }
164        if version >= 0 { n += 8; }
165        if version >= 0 { n += 8; }
166        if version >= 0 { n += 2; }
167        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
168        if flex {
169            let known_pairs: Vec<(u32, usize)> = Vec::new();
170            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
171        }
172        n
173    }
174}
175
176impl<'de> DecodeBorrow<'de> for TransactionState<'de> {
177    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
178        let flex = version >= 0;
179        let mut out = Self::default();
180        if version >= 0 { out.error_code = get_i16(buf)?; }
181        if version >= 0 { out.transactional_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
182        if version >= 0 { out.transaction_state = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
183        if version >= 0 { out.transaction_timeout_ms = get_i32(buf)?; }
184        if version >= 0 { out.transaction_start_time_ms = get_i64(buf)?; }
185        if version >= 0 { out.producer_id = get_i64(buf)?; }
186        if version >= 0 { out.producer_epoch = get_i16(buf)?; }
187        if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TopicData::decode_borrow(buf, version)?); } v }; }
188        if flex {
189            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
190                Ok(false)
191            })?;
192        }
193        Ok(out)
194    }
195}
196
197#[derive(Debug, Clone, PartialEq, Eq)]
198pub struct TopicData<'a> {
199    pub topic: &'a str,
200    pub partitions: Vec<i32>,
201    pub unknown_tagged_fields: UnknownTaggedFields,
202}
203
204impl<'a> Default for TopicData<'a> {
205    fn default() -> Self {
206        Self {
207            topic: "",
208            partitions: Vec::new(),
209            unknown_tagged_fields: Default::default(),
210        }
211    }
212}
213
214impl<'a> TopicData<'a> {
215    pub fn to_owned(&self) -> crate::owned::describe_transactions_response::TopicData {
216        crate::owned::describe_transactions_response::TopicData {
217            topic: (self.topic).to_string(),
218            partitions: (self.partitions).clone(),
219            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
220        }
221    }
222}
223
224impl<'a> Encode for TopicData<'a> {
225    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
226        let flex = version >= 0;
227        if version >= 0 { if flex { put_compact_string(buf, self.topic) } else { put_string(buf, self.topic) } }
228        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { put_i32(buf, *it); } } }
229        if flex {
230            let tagged = WriteTaggedFields::new();
231            tagged.write(buf, &self.unknown_tagged_fields);
232        }
233        Ok(())
234    }
235    fn encoded_len(&self, version: i16) -> usize {
236        let flex = version >= 0;
237        let mut n: usize = 0;
238        if version >= 0 { n += if flex { compact_string_len(self.topic) } else { string_len(self.topic) }; }
239        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|_| 4).sum(); prefix + body }; }
240        if flex {
241            let known_pairs: Vec<(u32, usize)> = Vec::new();
242            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
243        }
244        n
245    }
246}
247
248impl<'de> DecodeBorrow<'de> for TopicData<'de> {
249    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
250        let flex = version >= 0;
251        let mut out = Self::default();
252        if version >= 0 { out.topic = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
253        if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
254        if flex {
255            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
256                Ok(false)
257            })?;
258        }
259        Ok(out)
260    }
261}