kafka_protocol/messages/
list_transactions_response.rs

1//! ListTransactionsResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/ListTransactionsResponse.json).
4// WARNING: the items of this module are generated and should not be edited directly
5#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15    buf::{ByteBuf, ByteBufMut},
16    compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17    Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20/// Valid versions: 0-1
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct ListTransactionsResponse {
24    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
25    ///
26    /// Supported API versions: 0-1
27    pub throttle_time_ms: i32,
28
29    ///
30    ///
31    /// Supported API versions: 0-1
32    pub error_code: i16,
33
34    /// Set of state filters provided in the request which were unknown to the transaction coordinator
35    ///
36    /// Supported API versions: 0-1
37    pub unknown_state_filters: Vec<StrBytes>,
38
39    ///
40    ///
41    /// Supported API versions: 0-1
42    pub transaction_states: Vec<TransactionState>,
43
44    /// Other tagged fields
45    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
46}
47
48impl ListTransactionsResponse {
49    /// Sets `throttle_time_ms` to the passed value.
50    ///
51    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
52    ///
53    /// Supported API versions: 0-1
54    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
55        self.throttle_time_ms = value;
56        self
57    }
58    /// Sets `error_code` to the passed value.
59    ///
60    ///
61    ///
62    /// Supported API versions: 0-1
63    pub fn with_error_code(mut self, value: i16) -> Self {
64        self.error_code = value;
65        self
66    }
67    /// Sets `unknown_state_filters` to the passed value.
68    ///
69    /// Set of state filters provided in the request which were unknown to the transaction coordinator
70    ///
71    /// Supported API versions: 0-1
72    pub fn with_unknown_state_filters(mut self, value: Vec<StrBytes>) -> Self {
73        self.unknown_state_filters = value;
74        self
75    }
76    /// Sets `transaction_states` to the passed value.
77    ///
78    ///
79    ///
80    /// Supported API versions: 0-1
81    pub fn with_transaction_states(mut self, value: Vec<TransactionState>) -> Self {
82        self.transaction_states = value;
83        self
84    }
85    /// Sets unknown_tagged_fields to the passed value.
86    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
87        self.unknown_tagged_fields = value;
88        self
89    }
90    /// Inserts an entry into unknown_tagged_fields.
91    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
92        self.unknown_tagged_fields.insert(key, value);
93        self
94    }
95}
96
97#[cfg(feature = "broker")]
98impl Encodable for ListTransactionsResponse {
99    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
100        types::Int32.encode(buf, &self.throttle_time_ms)?;
101        types::Int16.encode(buf, &self.error_code)?;
102        types::CompactArray(types::CompactString).encode(buf, &self.unknown_state_filters)?;
103        types::CompactArray(types::Struct { version }).encode(buf, &self.transaction_states)?;
104        let num_tagged_fields = self.unknown_tagged_fields.len();
105        if num_tagged_fields > std::u32::MAX as usize {
106            bail!(
107                "Too many tagged fields to encode ({} fields)",
108                num_tagged_fields
109            );
110        }
111        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
112
113        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
114        Ok(())
115    }
116    fn compute_size(&self, version: i16) -> Result<usize> {
117        let mut total_size = 0;
118        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
119        total_size += types::Int16.compute_size(&self.error_code)?;
120        total_size +=
121            types::CompactArray(types::CompactString).compute_size(&self.unknown_state_filters)?;
122        total_size += types::CompactArray(types::Struct { version })
123            .compute_size(&self.transaction_states)?;
124        let num_tagged_fields = self.unknown_tagged_fields.len();
125        if num_tagged_fields > std::u32::MAX as usize {
126            bail!(
127                "Too many tagged fields to encode ({} fields)",
128                num_tagged_fields
129            );
130        }
131        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
132
133        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
134        Ok(total_size)
135    }
136}
137
138#[cfg(feature = "client")]
139impl Decodable for ListTransactionsResponse {
140    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
141        let throttle_time_ms = types::Int32.decode(buf)?;
142        let error_code = types::Int16.decode(buf)?;
143        let unknown_state_filters = types::CompactArray(types::CompactString).decode(buf)?;
144        let transaction_states = types::CompactArray(types::Struct { version }).decode(buf)?;
145        let mut unknown_tagged_fields = BTreeMap::new();
146        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
147        for _ in 0..num_tagged_fields {
148            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
149            let size: u32 = types::UnsignedVarInt.decode(buf)?;
150            let unknown_value = buf.try_get_bytes(size as usize)?;
151            unknown_tagged_fields.insert(tag as i32, unknown_value);
152        }
153        Ok(Self {
154            throttle_time_ms,
155            error_code,
156            unknown_state_filters,
157            transaction_states,
158            unknown_tagged_fields,
159        })
160    }
161}
162
163impl Default for ListTransactionsResponse {
164    fn default() -> Self {
165        Self {
166            throttle_time_ms: 0,
167            error_code: 0,
168            unknown_state_filters: Default::default(),
169            transaction_states: Default::default(),
170            unknown_tagged_fields: BTreeMap::new(),
171        }
172    }
173}
174
175impl Message for ListTransactionsResponse {
176    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
177    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
178}
179
180/// Valid versions: 0-1
181#[non_exhaustive]
182#[derive(Debug, Clone, PartialEq)]
183pub struct TransactionState {
184    ///
185    ///
186    /// Supported API versions: 0-1
187    pub transactional_id: super::TransactionalId,
188
189    ///
190    ///
191    /// Supported API versions: 0-1
192    pub producer_id: super::ProducerId,
193
194    /// The current transaction state of the producer
195    ///
196    /// Supported API versions: 0-1
197    pub transaction_state: StrBytes,
198
199    /// Other tagged fields
200    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
201}
202
203impl TransactionState {
204    /// Sets `transactional_id` to the passed value.
205    ///
206    ///
207    ///
208    /// Supported API versions: 0-1
209    pub fn with_transactional_id(mut self, value: super::TransactionalId) -> Self {
210        self.transactional_id = value;
211        self
212    }
213    /// Sets `producer_id` to the passed value.
214    ///
215    ///
216    ///
217    /// Supported API versions: 0-1
218    pub fn with_producer_id(mut self, value: super::ProducerId) -> Self {
219        self.producer_id = value;
220        self
221    }
222    /// Sets `transaction_state` to the passed value.
223    ///
224    /// The current transaction state of the producer
225    ///
226    /// Supported API versions: 0-1
227    pub fn with_transaction_state(mut self, value: StrBytes) -> Self {
228        self.transaction_state = value;
229        self
230    }
231    /// Sets unknown_tagged_fields to the passed value.
232    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
233        self.unknown_tagged_fields = value;
234        self
235    }
236    /// Inserts an entry into unknown_tagged_fields.
237    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
238        self.unknown_tagged_fields.insert(key, value);
239        self
240    }
241}
242
243#[cfg(feature = "broker")]
244impl Encodable for TransactionState {
245    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
246        types::CompactString.encode(buf, &self.transactional_id)?;
247        types::Int64.encode(buf, &self.producer_id)?;
248        types::CompactString.encode(buf, &self.transaction_state)?;
249        let num_tagged_fields = self.unknown_tagged_fields.len();
250        if num_tagged_fields > std::u32::MAX as usize {
251            bail!(
252                "Too many tagged fields to encode ({} fields)",
253                num_tagged_fields
254            );
255        }
256        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
257
258        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
259        Ok(())
260    }
261    fn compute_size(&self, version: i16) -> Result<usize> {
262        let mut total_size = 0;
263        total_size += types::CompactString.compute_size(&self.transactional_id)?;
264        total_size += types::Int64.compute_size(&self.producer_id)?;
265        total_size += types::CompactString.compute_size(&self.transaction_state)?;
266        let num_tagged_fields = self.unknown_tagged_fields.len();
267        if num_tagged_fields > std::u32::MAX as usize {
268            bail!(
269                "Too many tagged fields to encode ({} fields)",
270                num_tagged_fields
271            );
272        }
273        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
274
275        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
276        Ok(total_size)
277    }
278}
279
280#[cfg(feature = "client")]
281impl Decodable for TransactionState {
282    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
283        let transactional_id = types::CompactString.decode(buf)?;
284        let producer_id = types::Int64.decode(buf)?;
285        let transaction_state = types::CompactString.decode(buf)?;
286        let mut unknown_tagged_fields = BTreeMap::new();
287        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
288        for _ in 0..num_tagged_fields {
289            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
290            let size: u32 = types::UnsignedVarInt.decode(buf)?;
291            let unknown_value = buf.try_get_bytes(size as usize)?;
292            unknown_tagged_fields.insert(tag as i32, unknown_value);
293        }
294        Ok(Self {
295            transactional_id,
296            producer_id,
297            transaction_state,
298            unknown_tagged_fields,
299        })
300    }
301}
302
303impl Default for TransactionState {
304    fn default() -> Self {
305        Self {
306            transactional_id: Default::default(),
307            producer_id: (0).into(),
308            transaction_state: Default::default(),
309            unknown_tagged_fields: BTreeMap::new(),
310        }
311    }
312}
313
314impl Message for TransactionState {
315    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
316    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
317}
318
319impl HeaderVersion for ListTransactionsResponse {
320    fn header_version(version: i16) -> i16 {
321        1
322    }
323}