kafka_protocol/messages/
list_transactions_request.rs

1//! ListTransactionsRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/ListTransactionsRequest.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 ListTransactionsRequest {
24    /// The transaction states to filter by: if empty, all transactions are returned; if non-empty, then only transactions matching one of the filtered states will be returned
25    ///
26    /// Supported API versions: 0-1
27    pub state_filters: Vec<StrBytes>,
28
29    /// The producerIds to filter by: if empty, all transactions will be returned; if non-empty, only transactions which match one of the filtered producerIds will be returned
30    ///
31    /// Supported API versions: 0-1
32    pub producer_id_filters: Vec<super::ProducerId>,
33
34    /// Duration (in millis) to filter by: if < 0, all transactions will be returned; otherwise, only transactions running longer than this duration will be returned
35    ///
36    /// Supported API versions: 1
37    pub duration_filter: i64,
38
39    /// Other tagged fields
40    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl ListTransactionsRequest {
44    /// Sets `state_filters` to the passed value.
45    ///
46    /// The transaction states to filter by: if empty, all transactions are returned; if non-empty, then only transactions matching one of the filtered states will be returned
47    ///
48    /// Supported API versions: 0-1
49    pub fn with_state_filters(mut self, value: Vec<StrBytes>) -> Self {
50        self.state_filters = value;
51        self
52    }
53    /// Sets `producer_id_filters` to the passed value.
54    ///
55    /// The producerIds to filter by: if empty, all transactions will be returned; if non-empty, only transactions which match one of the filtered producerIds will be returned
56    ///
57    /// Supported API versions: 0-1
58    pub fn with_producer_id_filters(mut self, value: Vec<super::ProducerId>) -> Self {
59        self.producer_id_filters = value;
60        self
61    }
62    /// Sets `duration_filter` to the passed value.
63    ///
64    /// Duration (in millis) to filter by: if < 0, all transactions will be returned; otherwise, only transactions running longer than this duration will be returned
65    ///
66    /// Supported API versions: 1
67    pub fn with_duration_filter(mut self, value: i64) -> Self {
68        self.duration_filter = value;
69        self
70    }
71    /// Sets unknown_tagged_fields to the passed value.
72    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73        self.unknown_tagged_fields = value;
74        self
75    }
76    /// Inserts an entry into unknown_tagged_fields.
77    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
78        self.unknown_tagged_fields.insert(key, value);
79        self
80    }
81}
82
83#[cfg(feature = "client")]
84impl Encodable for ListTransactionsRequest {
85    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86        if version < 0 || version > 1 {
87            bail!("specified version not supported by this message type");
88        }
89        types::CompactArray(types::CompactString).encode(buf, &self.state_filters)?;
90        types::CompactArray(types::Int64).encode(buf, &self.producer_id_filters)?;
91        if version >= 1 {
92            types::Int64.encode(buf, &self.duration_filter)?;
93        } else {
94            if self.duration_filter != -1 {
95                bail!("A field is set that is not available on the selected protocol version");
96            }
97        }
98        let num_tagged_fields = self.unknown_tagged_fields.len();
99        if num_tagged_fields > std::u32::MAX as usize {
100            bail!(
101                "Too many tagged fields to encode ({} fields)",
102                num_tagged_fields
103            );
104        }
105        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
106
107        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
108        Ok(())
109    }
110    fn compute_size(&self, version: i16) -> Result<usize> {
111        let mut total_size = 0;
112        total_size +=
113            types::CompactArray(types::CompactString).compute_size(&self.state_filters)?;
114        total_size += types::CompactArray(types::Int64).compute_size(&self.producer_id_filters)?;
115        if version >= 1 {
116            total_size += types::Int64.compute_size(&self.duration_filter)?;
117        } else {
118            if self.duration_filter != -1 {
119                bail!("A field is set that is not available on the selected protocol version");
120            }
121        }
122        let num_tagged_fields = self.unknown_tagged_fields.len();
123        if num_tagged_fields > std::u32::MAX as usize {
124            bail!(
125                "Too many tagged fields to encode ({} fields)",
126                num_tagged_fields
127            );
128        }
129        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
130
131        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
132        Ok(total_size)
133    }
134}
135
136#[cfg(feature = "broker")]
137impl Decodable for ListTransactionsRequest {
138    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
139        if version < 0 || version > 1 {
140            bail!("specified version not supported by this message type");
141        }
142        let state_filters = types::CompactArray(types::CompactString).decode(buf)?;
143        let producer_id_filters = types::CompactArray(types::Int64).decode(buf)?;
144        let duration_filter = if version >= 1 {
145            types::Int64.decode(buf)?
146        } else {
147            -1
148        };
149        let mut unknown_tagged_fields = BTreeMap::new();
150        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
151        for _ in 0..num_tagged_fields {
152            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
153            let size: u32 = types::UnsignedVarInt.decode(buf)?;
154            let unknown_value = buf.try_get_bytes(size as usize)?;
155            unknown_tagged_fields.insert(tag as i32, unknown_value);
156        }
157        Ok(Self {
158            state_filters,
159            producer_id_filters,
160            duration_filter,
161            unknown_tagged_fields,
162        })
163    }
164}
165
166impl Default for ListTransactionsRequest {
167    fn default() -> Self {
168        Self {
169            state_filters: Default::default(),
170            producer_id_filters: Default::default(),
171            duration_filter: -1,
172            unknown_tagged_fields: BTreeMap::new(),
173        }
174    }
175}
176
177impl Message for ListTransactionsRequest {
178    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
179    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
180}
181
182impl HeaderVersion for ListTransactionsRequest {
183    fn header_version(version: i16) -> i16 {
184        2
185    }
186}