Skip to main content

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

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