Skip to main content

kacrab_protocol/generated/
list_transactions_request.rs

1//! Generated from ListTransactionsRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct ListTransactionsRequestData {
17    /// The transaction states to filter by: if empty, all transactions are returned; if non-empty,
18    /// then only transactions matching one of the filtered states will be returned.
19    pub state_filters: Vec<KafkaString>,
20    /// The producerIds to filter by: if empty, all transactions will be returned; if non-empty,
21    /// only transactions which match one of the filtered producerIds will be returned.
22    pub producer_id_filters: Vec<i64>,
23    /// Duration (in millis) to filter by: if < 0, all transactions will be returned; otherwise,
24    /// only transactions running longer than this duration will be returned.
25    pub duration_filter: i64,
26    /// The transactional ID regular expression pattern to filter by: if it is empty or null, all
27    /// transactions are returned; Otherwise then only the transactions matching the given regular
28    /// expression will be returned.
29    pub transactional_id_pattern: Option<KafkaString>,
30    pub _unknown_tagged_fields: Vec<RawTaggedField>,
31}
32impl Default for ListTransactionsRequestData {
33    fn default() -> Self {
34        Self {
35            state_filters: Vec::new(),
36            producer_id_filters: Vec::new(),
37            duration_filter: -1i64,
38            transactional_id_pattern: None,
39            _unknown_tagged_fields: Vec::new(),
40        }
41    }
42}
43impl ListTransactionsRequestData {
44    pub fn with_state_filters(mut self, value: Vec<KafkaString>) -> Self {
45        self.state_filters = value;
46        self
47    }
48    pub fn with_producer_id_filters(mut self, value: Vec<i64>) -> Self {
49        self.producer_id_filters = value;
50        self
51    }
52    pub fn with_duration_filter(mut self, value: i64) -> Self {
53        self.duration_filter = value;
54        self
55    }
56    pub fn with_transactional_id_pattern(mut self, value: Option<KafkaString>) -> Self {
57        self.transactional_id_pattern = value;
58        self
59    }
60    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
61        if version < 0 || version > 2 {
62            return Err(UnsupportedVersion::new(66, version).into());
63        }
64        let state_filters;
65        let producer_id_filters;
66        let mut duration_filter = -1i64;
67        let mut transactional_id_pattern = None;
68        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
69        state_filters = {
70            let len = read_compact_array_length(buf)?;
71            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
72            for _ in 0..len {
73                arr.push(read_compact_string(buf)?);
74            }
75            arr
76        };
77        producer_id_filters = {
78            let len = read_compact_array_length(buf)?;
79            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
80            for _ in 0..len {
81                arr.push(read_i64(buf)?);
82            }
83            arr
84        };
85        if version >= 1 {
86            duration_filter = read_i64(buf)?;
87        }
88        if version >= 2 {
89            transactional_id_pattern = read_compact_nullable_string(buf)?;
90        }
91        let tagged_fields = read_tagged_fields(buf)?;
92        for field in &tagged_fields {
93            match field.tag {
94                _ => {
95                    _unknown_tagged_fields.push(field.clone());
96                },
97            }
98        }
99        Ok(Self {
100            state_filters,
101            producer_id_filters,
102            duration_filter,
103            transactional_id_pattern,
104            _unknown_tagged_fields,
105        })
106    }
107    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
108        if version < 0 || version > 2 {
109            return Err(UnsupportedVersion::new(66, version).into());
110        }
111        write_compact_array_length(buf, self.state_filters.len() as i32);
112        for el in &self.state_filters {
113            write_compact_string(buf, el)?;
114        }
115        write_compact_array_length(buf, self.producer_id_filters.len() as i32);
116        for el in &self.producer_id_filters {
117            write_i64(buf, *el);
118        }
119        if version >= 1 {
120            write_i64(buf, self.duration_filter);
121        } else if self.duration_filter != -1i64 {
122            return Err(UnsupportedFieldVersion::new(66, "duration_filter", version).into());
123        }
124        if version >= 2 {
125            write_compact_nullable_string(buf, self.transactional_id_pattern.as_ref())?;
126        } else if self.transactional_id_pattern != None {
127            return Err(
128                UnsupportedFieldVersion::new(66, "transactional_id_pattern", version).into(),
129            );
130        }
131        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
132        all_tags.sort_by_key(|f| f.tag);
133        write_tagged_fields(buf, &all_tags)?;
134        Ok(())
135    }
136    pub fn encoded_len(&self, version: i16) -> Result<usize> {
137        if version < 0 || version > 2 {
138            return Err(UnsupportedVersion::new(66, version).into());
139        }
140        let mut len: usize = 0;
141        len += compact_array_length_len(self.state_filters.len() as i32);
142        for el in &self.state_filters {
143            len += compact_string_len(el)?;
144        }
145        len += compact_array_length_len(self.producer_id_filters.len() as i32);
146        len += self.producer_id_filters.len() * 8usize;
147        if version >= 1 {
148            len += 8;
149        } else if self.duration_filter != -1i64 {
150            return Err(UnsupportedFieldVersion::new(66, "duration_filter", version).into());
151        }
152        if version >= 2 {
153            len += compact_nullable_string_len(self.transactional_id_pattern.as_ref())?;
154        } else if self.transactional_id_pattern != None {
155            return Err(
156                UnsupportedFieldVersion::new(66, "transactional_id_pattern", version).into(),
157            );
158        }
159        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
160        all_tags.sort_by_key(|f| f.tag);
161        len += tagged_fields_len(&all_tags)?;
162        Ok(len)
163    }
164}