Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeTransactionsResponse.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 = 65;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
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 DescribeTransactionsResponse {
23    pub throttle_time_ms: i32,
24    pub transaction_states: Vec<TransactionState>,
25    pub unknown_tagged_fields: UnknownTaggedFields,
26}
27
28impl Encode for DescribeTransactionsResponse {
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 { api_key: API_KEY, version });
32        }
33        let flex = is_flexible(version);
34        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
35        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)?; } } }
36        if flex {
37            let tagged = WriteTaggedFields::new();
38            tagged.write(buf, &self.unknown_tagged_fields);
39        }
40        Ok(())
41    }
42    fn encoded_len(&self, version: i16) -> usize {
43        let flex = is_flexible(version);
44        let mut n: usize = 0;
45        if version >= 0 { n += 4; }
46        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 }; }
47        if flex {
48            let known_pairs: Vec<(u32, usize)> = Vec::new();
49            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
50        }
51        n
52    }
53}
54
55impl<'de> Decode<'de> for DescribeTransactionsResponse {
56    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
57        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
58            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
59        }
60        let flex = is_flexible(version);
61        let mut out = Self::default();
62        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
63        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 }; }
64        if flex {
65            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
66                Ok(false)
67            })?;
68        }
69        Ok(out)
70    }
71}
72
73#[derive(Debug, Clone, PartialEq, Eq, Default)]
74pub struct TransactionState {
75    pub error_code: i16,
76    pub transactional_id: String,
77    pub transaction_state: String,
78    pub transaction_timeout_ms: i32,
79    pub transaction_start_time_ms: i64,
80    pub producer_id: i64,
81    pub producer_epoch: i16,
82    pub topics: Vec<TopicData>,
83    pub unknown_tagged_fields: UnknownTaggedFields,
84}
85
86impl Encode for TransactionState {
87    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
88        let flex = version >= 0;
89        if version >= 0 { put_i16(buf, self.error_code) }
90        if version >= 0 { if flex { put_compact_string(buf, &self.transactional_id) } else { put_string(buf, &self.transactional_id) } }
91        if version >= 0 { if flex { put_compact_string(buf, &self.transaction_state) } else { put_string(buf, &self.transaction_state) } }
92        if version >= 0 { put_i32(buf, self.transaction_timeout_ms) }
93        if version >= 0 { put_i64(buf, self.transaction_start_time_ms) }
94        if version >= 0 { put_i64(buf, self.producer_id) }
95        if version >= 0 { put_i16(buf, self.producer_epoch) }
96        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
97        if flex {
98            let tagged = WriteTaggedFields::new();
99            tagged.write(buf, &self.unknown_tagged_fields);
100        }
101        Ok(())
102    }
103    fn encoded_len(&self, version: i16) -> usize {
104        let flex = version >= 0;
105        let mut n: usize = 0;
106        if version >= 0 { n += 2; }
107        if version >= 0 { n += if flex { compact_string_len(&self.transactional_id) } else { string_len(&self.transactional_id) }; }
108        if version >= 0 { n += if flex { compact_string_len(&self.transaction_state) } else { string_len(&self.transaction_state) }; }
109        if version >= 0 { n += 4; }
110        if version >= 0 { n += 8; }
111        if version >= 0 { n += 8; }
112        if version >= 0 { n += 2; }
113        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
114        if flex {
115            let known_pairs: Vec<(u32, usize)> = Vec::new();
116            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
117        }
118        n
119    }
120}
121
122impl<'de> Decode<'de> for TransactionState {
123    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
124        let flex = version >= 0;
125        let mut out = Self::default();
126        if version >= 0 { out.error_code = get_i16(buf)?; }
127        if version >= 0 { out.transactional_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
128        if version >= 0 { out.transaction_state = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
129        if version >= 0 { out.transaction_timeout_ms = get_i32(buf)?; }
130        if version >= 0 { out.transaction_start_time_ms = get_i64(buf)?; }
131        if version >= 0 { out.producer_id = get_i64(buf)?; }
132        if version >= 0 { out.producer_epoch = get_i16(buf)?; }
133        if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TopicData::decode(buf, version)?); } v }; }
134        if flex {
135            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
136                Ok(false)
137            })?;
138        }
139        Ok(out)
140    }
141}
142
143#[derive(Debug, Clone, PartialEq, Eq, Default)]
144pub struct TopicData {
145    pub topic: String,
146    pub partitions: Vec<i32>,
147    pub unknown_tagged_fields: UnknownTaggedFields,
148}
149
150impl Encode for TopicData {
151    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
152        let flex = version >= 0;
153        if version >= 0 { if flex { put_compact_string(buf, &self.topic) } else { put_string(buf, &self.topic) } }
154        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { put_i32(buf, *it); } } }
155        if flex {
156            let tagged = WriteTaggedFields::new();
157            tagged.write(buf, &self.unknown_tagged_fields);
158        }
159        Ok(())
160    }
161    fn encoded_len(&self, version: i16) -> usize {
162        let flex = version >= 0;
163        let mut n: usize = 0;
164        if version >= 0 { n += if flex { compact_string_len(&self.topic) } else { string_len(&self.topic) }; }
165        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|_| 4).sum(); prefix + body }; }
166        if flex {
167            let known_pairs: Vec<(u32, usize)> = Vec::new();
168            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
169        }
170        n
171    }
172}
173
174impl<'de> Decode<'de> for TopicData {
175    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
176        let flex = version >= 0;
177        let mut out = Self::default();
178        if version >= 0 { out.topic = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
179        if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
180        if flex {
181            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
182                Ok(false)
183            })?;
184        }
185        Ok(out)
186    }
187}
188
189/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
190/// Only includes fields valid for the given version.
191#[must_use]
192#[allow(unused_comparisons)]
193pub fn default_json(version: i16) -> ::serde_json::Value {
194    let mut obj = ::serde_json::Map::new();
195    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
196    obj.insert("transactionStates".to_string(), ::serde_json::Value::Array(vec![]));
197    ::serde_json::Value::Object(obj)
198}