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