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