Skip to main content

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

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