Skip to main content

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

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