Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ListTransactionsRequest.borrowed.rs

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