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        types::CompactArray(types::CompactString).encode(buf, &self.state_filters)?;
87        types::CompactArray(types::Int64).encode(buf, &self.producer_id_filters)?;
88        if version >= 1 {
89            types::Int64.encode(buf, &self.duration_filter)?;
90        } else {
91            if self.duration_filter != -1 {
92                bail!("A field is set that is not available on the selected protocol version");
93            }
94        }
95        let num_tagged_fields = self.unknown_tagged_fields.len();
96        if num_tagged_fields > std::u32::MAX as usize {
97            bail!(
98                "Too many tagged fields to encode ({} fields)",
99                num_tagged_fields
100            );
101        }
102        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
103
104        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
105        Ok(())
106    }
107    fn compute_size(&self, version: i16) -> Result<usize> {
108        let mut total_size = 0;
109        total_size +=
110            types::CompactArray(types::CompactString).compute_size(&self.state_filters)?;
111        total_size += types::CompactArray(types::Int64).compute_size(&self.producer_id_filters)?;
112        if version >= 1 {
113            total_size += types::Int64.compute_size(&self.duration_filter)?;
114        } else {
115            if self.duration_filter != -1 {
116                bail!("A field is set that is not available on the selected protocol version");
117            }
118        }
119        let num_tagged_fields = self.unknown_tagged_fields.len();
120        if num_tagged_fields > std::u32::MAX as usize {
121            bail!(
122                "Too many tagged fields to encode ({} fields)",
123                num_tagged_fields
124            );
125        }
126        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
127
128        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
129        Ok(total_size)
130    }
131}
132
133#[cfg(feature = "broker")]
134impl Decodable for ListTransactionsRequest {
135    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
136        let state_filters = types::CompactArray(types::CompactString).decode(buf)?;
137        let producer_id_filters = types::CompactArray(types::Int64).decode(buf)?;
138        let duration_filter = if version >= 1 {
139            types::Int64.decode(buf)?
140        } else {
141            -1
142        };
143        let mut unknown_tagged_fields = BTreeMap::new();
144        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
145        for _ in 0..num_tagged_fields {
146            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
147            let size: u32 = types::UnsignedVarInt.decode(buf)?;
148            let unknown_value = buf.try_get_bytes(size as usize)?;
149            unknown_tagged_fields.insert(tag as i32, unknown_value);
150        }
151        Ok(Self {
152            state_filters,
153            producer_id_filters,
154            duration_filter,
155            unknown_tagged_fields,
156        })
157    }
158}
159
160impl Default for ListTransactionsRequest {
161    fn default() -> Self {
162        Self {
163            state_filters: Default::default(),
164            producer_id_filters: Default::default(),
165            duration_filter: -1,
166            unknown_tagged_fields: BTreeMap::new(),
167        }
168    }
169}
170
171impl Message for ListTransactionsRequest {
172    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
173    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
174}
175
176impl HeaderVersion for ListTransactionsRequest {
177    fn header_version(version: i16) -> i16 {
178        2
179    }
180}