Skip to main content

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

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