Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeTransactionsRequest.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::string_bytes::{
8        compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
9        put_string, string_len,
10    },
11    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 65;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const LATEST_STABLE_VERSION: i16 = 0;
17pub const FLEXIBLE_MIN: i16 = 0;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21    version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct DescribeTransactionsRequest {
25    pub transactional_ids: Vec<String>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl Encode for DescribeTransactionsRequest {
29    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
30        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
31            return Err(ProtocolError::UnsupportedVersion {
32                api_key: API_KEY,
33                version,
34            });
35        }
36        let flex = is_flexible(version);
37        if version >= 0 {
38            {
39                crate::primitives::array::put_array_len(buf, (self.transactional_ids).len(), flex);
40                for it in &self.transactional_ids {
41                    if flex {
42                        let () = put_compact_string(buf, it);
43                    } else {
44                        let () = put_string(buf, it);
45                    }
46                }
47            };
48        }
49        if flex {
50            let tagged = WriteTaggedFields::new();
51            tagged.write(buf, &self.unknown_tagged_fields);
52        }
53        Ok(())
54    }
55    fn encoded_len(&self, version: i16) -> usize {
56        let flex = is_flexible(version);
57        let mut n: usize = 0;
58        if version >= 0 {
59            n += {
60                let prefix = crate::primitives::array::array_len_prefix_len(
61                    (self.transactional_ids).len(),
62                    flex,
63                );
64                let body: usize = (self.transactional_ids)
65                    .iter()
66                    .map(|it| {
67                        if flex {
68                            compact_string_len(it)
69                        } else {
70                            string_len(it)
71                        }
72                    })
73                    .sum();
74                prefix + body
75            };
76        }
77        if flex {
78            let known_pairs: Vec<(u32, usize)> = Vec::new();
79            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
80        }
81        n
82    }
83}
84impl Decode<'_> for DescribeTransactionsRequest {
85    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
86        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
87            return Err(ProtocolError::UnsupportedVersion {
88                api_key: API_KEY,
89                version,
90            });
91        }
92        let flex = is_flexible(version);
93        let mut out = Self::default();
94        if version >= 0 {
95            out.transactional_ids = {
96                let n = crate::primitives::array::get_array_len(buf, flex)?;
97                let mut v = Vec::with_capacity(n);
98                for _ in 0..n {
99                    v.push(if flex {
100                        get_compact_string_owned(buf)?
101                    } else {
102                        get_string_owned(buf)?
103                    });
104                }
105                v
106            };
107        }
108        if flex {
109            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
110        }
111        Ok(out)
112    }
113}
114#[cfg(test)]
115impl DescribeTransactionsRequest {
116    #[must_use]
117    pub fn populated(version: i16) -> Self {
118        let mut m = Self::default();
119        if version >= 0 {
120            m.transactional_ids = vec!["x".to_string()];
121        }
122        m
123    }
124}
125/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
126/// Only includes fields valid for the given version.
127#[must_use]
128#[allow(unused_comparisons)]
129pub fn default_json(_version: i16) -> ::serde_json::Value {
130    let mut obj = ::serde_json::Map::new();
131    obj.insert(
132        "transactionalIds".to_string(),
133        ::serde_json::Value::Array(vec![]),
134    );
135    ::serde_json::Value::Object(obj)
136}
137impl crate::ProtocolRequest for DescribeTransactionsRequest {
138    const API_KEY: i16 = API_KEY;
139    const MIN_VERSION: i16 = MIN_VERSION;
140    const MAX_VERSION: i16 = MAX_VERSION;
141    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
142    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
143    type Response = super::describe_transactions_response::DescribeTransactionsResponse;
144}