crabka_protocol/opt/rustwide/workdir/generated/
ListTransactionsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i64, put_i64};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
10};
11use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
12use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
13
14pub const API_KEY: i16 = 66;
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 2;
17pub const FLEXIBLE_MIN: i16 = 0;
18
19#[inline]
20fn is_flexible(version: i16) -> bool {
21 version >= FLEXIBLE_MIN
22}
23
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub struct ListTransactionsRequest {
26 pub state_filters: Vec<String>,
27 pub producer_id_filters: Vec<i64>,
28 pub duration_filter: i64,
29 pub transactional_id_pattern: Option<String>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Default for ListTransactionsRequest {
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: Default::default(),
40 }
41 }
42}
43impl Encode for ListTransactionsRequest {
44 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
45 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
46 return Err(ProtocolError::UnsupportedVersion {
47 api_key: API_KEY,
48 version,
49 });
50 }
51 let flex = is_flexible(version);
52 if version >= 0 {
53 {
54 crate::primitives::array::put_array_len(buf, (self.state_filters).len(), flex);
55 for it in &self.state_filters {
56 if flex {
57 put_compact_string(buf, it);
58 } else {
59 put_string(buf, it);
60 }
61 }
62 }
63 }
64 if version >= 0 {
65 {
66 crate::primitives::array::put_array_len(
67 buf,
68 (self.producer_id_filters).len(),
69 flex,
70 );
71 for it in &self.producer_id_filters {
72 put_i64(buf, *it);
73 }
74 }
75 }
76 if version >= 1 {
77 put_i64(buf, self.duration_filter);
78 }
79 if version >= 2 {
80 if flex {
81 put_compact_nullable_string(buf, self.transactional_id_pattern.as_deref());
82 } else {
83 put_nullable_string(buf, self.transactional_id_pattern.as_deref());
84 }
85 }
86 if flex {
87 let tagged = WriteTaggedFields::new();
88 tagged.write(buf, &self.unknown_tagged_fields);
89 }
90 Ok(())
91 }
92 fn encoded_len(&self, version: i16) -> usize {
93 let flex = is_flexible(version);
94 let mut n: usize = 0;
95 if version >= 0 {
96 n += {
97 let prefix = crate::primitives::array::array_len_prefix_len(
98 (self.state_filters).len(),
99 flex,
100 );
101 let body: usize = (self.state_filters)
102 .iter()
103 .map(|it| {
104 if flex {
105 compact_string_len(it)
106 } else {
107 string_len(it)
108 }
109 })
110 .sum();
111 prefix + body
112 };
113 }
114 if version >= 0 {
115 n += {
116 let prefix = crate::primitives::array::array_len_prefix_len(
117 (self.producer_id_filters).len(),
118 flex,
119 );
120 let body: usize = (self.producer_id_filters).iter().map(|_| 8).sum();
121 prefix + body
122 };
123 }
124 if version >= 1 {
125 n += 8;
126 }
127 if version >= 2 {
128 n += if flex {
129 compact_nullable_string_len(self.transactional_id_pattern.as_deref())
130 } else {
131 nullable_string_len(self.transactional_id_pattern.as_deref())
132 };
133 }
134 if flex {
135 let known_pairs: Vec<(u32, usize)> = Vec::new();
136 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
137 }
138 n
139 }
140}
141impl Decode<'_> for ListTransactionsRequest {
142 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
143 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
144 return Err(ProtocolError::UnsupportedVersion {
145 api_key: API_KEY,
146 version,
147 });
148 }
149 let flex = is_flexible(version);
150 let mut out = Self::default();
151 if version >= 0 {
152 out.state_filters = {
153 let n = crate::primitives::array::get_array_len(buf, flex)?;
154 let mut v = Vec::with_capacity(n);
155 for _ in 0..n {
156 v.push(if flex {
157 get_compact_string_owned(buf)?
158 } else {
159 get_string_owned(buf)?
160 });
161 }
162 v
163 };
164 }
165 if version >= 0 {
166 out.producer_id_filters = {
167 let n = crate::primitives::array::get_array_len(buf, flex)?;
168 let mut v = Vec::with_capacity(n);
169 for _ in 0..n {
170 v.push(get_i64(buf)?);
171 }
172 v
173 };
174 }
175 if version >= 1 {
176 out.duration_filter = get_i64(buf)?;
177 }
178 if version >= 2 {
179 out.transactional_id_pattern = if flex {
180 get_compact_nullable_string_owned(buf)?
181 } else {
182 get_nullable_string_owned(buf)?
183 };
184 }
185 if flex {
186 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
187 }
188 Ok(out)
189 }
190}
191#[cfg(test)]
192impl ListTransactionsRequest {
193 #[must_use]
194 pub fn populated(version: i16) -> Self {
195 let mut m = Self::default();
196 if version >= 0 {
197 m.state_filters = vec!["x".to_string()];
198 }
199 if version >= 0 {
200 m.producer_id_filters = vec![1i64];
201 }
202 if version >= 1 {
203 m.duration_filter = 1i64;
204 }
205 if version >= 2 {
206 m.transactional_id_pattern = Some("x".to_string());
207 }
208 m
209 }
210}
211
212#[must_use]
215#[allow(unused_comparisons)]
216pub fn default_json(version: i16) -> ::serde_json::Value {
217 let mut obj = ::serde_json::Map::new();
218 obj.insert(
219 "stateFilters".to_string(),
220 ::serde_json::Value::Array(vec![]),
221 );
222 obj.insert(
223 "producerIdFilters".to_string(),
224 ::serde_json::Value::Array(vec![]),
225 );
226 if version >= 1 {
227 obj.insert("durationFilter".to_string(), ::serde_json::json!(-1));
228 }
229 if version >= 2 {
230 obj.insert(
231 "transactionalIdPattern".to_string(),
232 ::serde_json::Value::Null,
233 );
234 }
235 ::serde_json::Value::Object(obj)
236}
237
238impl crate::ProtocolRequest for ListTransactionsRequest {
239 const API_KEY: i16 = API_KEY;
240 const MIN_VERSION: i16 = MIN_VERSION;
241 const MAX_VERSION: i16 = MAX_VERSION;
242 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
243 type Response = super::list_transactions_response::ListTransactionsResponse;
244}