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