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