Skip to main content

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

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