Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::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, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{
10    get_compact_string_borrowed, get_string_borrowed,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 66;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 2;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct ListTransactionsResponse<'a> {
25    pub throttle_time_ms: i32,
26    pub error_code: i16,
27    pub unknown_state_filters: Vec<&'a str>,
28    pub transaction_states: Vec<TransactionState<'a>>,
29    pub unknown_tagged_fields: UnknownTaggedFields,
30}
31
32impl<'a> Default for ListTransactionsResponse<'a> {
33    fn default() -> Self {
34        Self {
35            throttle_time_ms: 0i32,
36            error_code: 0i16,
37            unknown_state_filters: Vec::new(),
38            transaction_states: Vec::new(),
39            unknown_tagged_fields: Default::default(),
40        }
41    }
42}
43
44impl<'a> ListTransactionsResponse<'a> {
45    pub fn to_owned(&self) -> crate::owned::list_transactions_response::ListTransactionsResponse {
46        crate::owned::list_transactions_response::ListTransactionsResponse {
47            throttle_time_ms: (self.throttle_time_ms),
48            error_code: (self.error_code),
49            unknown_state_filters: (self.unknown_state_filters).iter().map(|s| s.to_string()).collect(),
50            transaction_states: (self.transaction_states).iter().map(|it| it.to_owned()).collect(),
51            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
52        }
53    }
54}
55
56impl<'a> Encode for ListTransactionsResponse<'a> {
57    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
58        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
59            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
60        }
61        let flex = is_flexible(version);
62        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
63        if version >= 0 { put_i16(buf, self.error_code) }
64        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) }; } } }
65        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)?; } } }
66        if flex {
67            let tagged = WriteTaggedFields::new();
68            tagged.write(buf, &self.unknown_tagged_fields);
69        }
70        Ok(())
71    }
72    fn encoded_len(&self, version: i16) -> usize {
73        let flex = is_flexible(version);
74        let mut n: usize = 0;
75        if version >= 0 { n += 4; }
76        if version >= 0 { n += 2; }
77        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 }; }
78        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 }; }
79        if flex {
80            let known_pairs: Vec<(u32, usize)> = Vec::new();
81            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
82        }
83        n
84    }
85}
86
87impl<'de> DecodeBorrow<'de> for ListTransactionsResponse<'de> {
88    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
89        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
90            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
91        }
92        let flex = is_flexible(version);
93        let mut out = Self::default();
94        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
95        if version >= 0 { out.error_code = get_i16(buf)?; }
96        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_borrowed(buf)? } else { get_string_borrowed(buf)? }); } v }; }
97        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_borrow(buf, version)?); } v }; }
98        if flex {
99            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
100                Ok(false)
101            })?;
102        }
103        Ok(out)
104    }
105}
106
107#[derive(Debug, Clone, PartialEq, Eq)]
108pub struct TransactionState<'a> {
109    pub transactional_id: &'a str,
110    pub producer_id: i64,
111    pub transaction_state: &'a str,
112    pub unknown_tagged_fields: UnknownTaggedFields,
113}
114
115impl<'a> Default for TransactionState<'a> {
116    fn default() -> Self {
117        Self {
118            transactional_id: "",
119            producer_id: 0i64,
120            transaction_state: "",
121            unknown_tagged_fields: Default::default(),
122        }
123    }
124}
125
126impl<'a> TransactionState<'a> {
127    pub fn to_owned(&self) -> crate::owned::list_transactions_response::TransactionState {
128        crate::owned::list_transactions_response::TransactionState {
129            transactional_id: (self.transactional_id).to_string(),
130            producer_id: (self.producer_id),
131            transaction_state: (self.transaction_state).to_string(),
132            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
133        }
134    }
135}
136
137impl<'a> Encode for TransactionState<'a> {
138    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
139        let flex = version >= 0;
140        if version >= 0 { if flex { put_compact_string(buf, self.transactional_id) } else { put_string(buf, self.transactional_id) } }
141        if version >= 0 { put_i64(buf, self.producer_id) }
142        if version >= 0 { if flex { put_compact_string(buf, self.transaction_state) } else { put_string(buf, self.transaction_state) } }
143        if flex {
144            let tagged = WriteTaggedFields::new();
145            tagged.write(buf, &self.unknown_tagged_fields);
146        }
147        Ok(())
148    }
149    fn encoded_len(&self, version: i16) -> usize {
150        let flex = version >= 0;
151        let mut n: usize = 0;
152        if version >= 0 { n += if flex { compact_string_len(self.transactional_id) } else { string_len(self.transactional_id) }; }
153        if version >= 0 { n += 8; }
154        if version >= 0 { n += if flex { compact_string_len(self.transaction_state) } else { string_len(self.transaction_state) }; }
155        if flex {
156            let known_pairs: Vec<(u32, usize)> = Vec::new();
157            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
158        }
159        n
160    }
161}
162
163impl<'de> DecodeBorrow<'de> for TransactionState<'de> {
164    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
165        let flex = version >= 0;
166        let mut out = Self::default();
167        if version >= 0 { out.transactional_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
168        if version >= 0 { out.producer_id = get_i64(buf)?; }
169        if version >= 0 { out.transaction_state = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
170        if flex {
171            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
172                Ok(false)
173            })?;
174        }
175        Ok(out)
176    }
177}