crabka_protocol/opt/rustwide/workdir/generated/
AddPartitionsToTxnRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i64, put_bool, put_i16, 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 = 24;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 5;
16pub const FLEXIBLE_MIN: i16 = 3;
17
18#[inline]
19fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct AddPartitionsToTxnRequest {
23 pub transactions: Vec<AddPartitionsToTxnTransaction>,
24 pub v3_and_below_transactional_id: String,
25 pub v3_and_below_producer_id: i64,
26 pub v3_and_below_producer_epoch: i16,
27 pub v3_and_below_topics: Vec<super::common::add_partitions_to_txn_topic::AddPartitionsToTxnTopic>,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl Encode for AddPartitionsToTxnRequest {
32 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
35 }
36 let flex = is_flexible(version);
37 if version >= 4 { { crate::primitives::array::put_array_len(buf, (self.transactions).len(), flex); for it in &self.transactions { it.encode(buf, version)?; } } }
38 if version >= 0 && version <= 3 { if flex { put_compact_string(buf, &self.v3_and_below_transactional_id) } else { put_string(buf, &self.v3_and_below_transactional_id) } }
39 if version >= 0 && version <= 3 { put_i64(buf, self.v3_and_below_producer_id) }
40 if version >= 0 && version <= 3 { put_i16(buf, self.v3_and_below_producer_epoch) }
41 if version >= 0 && version <= 3 { { crate::primitives::array::put_array_len(buf, (self.v3_and_below_topics).len(), flex); for it in &self.v3_and_below_topics { it.encode(buf, version)?; } } }
42 if flex {
43 let tagged = WriteTaggedFields::new();
44 tagged.write(buf, &self.unknown_tagged_fields);
45 }
46 Ok(())
47 }
48 fn encoded_len(&self, version: i16) -> usize {
49 let flex = is_flexible(version);
50 let mut n: usize = 0;
51 if version >= 4 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.transactions).len(), flex); let body: usize = (self.transactions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
52 if version >= 0 && version <= 3 { n += if flex { compact_string_len(&self.v3_and_below_transactional_id) } else { string_len(&self.v3_and_below_transactional_id) }; }
53 if version >= 0 && version <= 3 { n += 8; }
54 if version >= 0 && version <= 3 { n += 2; }
55 if version >= 0 && version <= 3 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.v3_and_below_topics).len(), flex); let body: usize = (self.v3_and_below_topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
56 if flex {
57 let known_pairs: Vec<(u32, usize)> = Vec::new();
58 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
59 }
60 n
61 }
62}
63
64impl<'de> Decode<'de> for AddPartitionsToTxnRequest {
65 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
66 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
67 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
68 }
69 let flex = is_flexible(version);
70 let mut out = Self::default();
71 if version >= 4 { out.transactions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AddPartitionsToTxnTransaction::decode(buf, version)?); } v }; }
72 if version >= 0 && version <= 3 { out.v3_and_below_transactional_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
73 if version >= 0 && version <= 3 { out.v3_and_below_producer_id = get_i64(buf)?; }
74 if version >= 0 && version <= 3 { out.v3_and_below_producer_epoch = get_i16(buf)?; }
75 if version >= 0 && version <= 3 { out.v3_and_below_topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::add_partitions_to_txn_topic::AddPartitionsToTxnTopic::decode(buf, version)?); } v }; }
76 if flex {
77 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
78 Ok(false)
79 })?;
80 }
81 Ok(out)
82 }
83}
84
85#[derive(Debug, Clone, PartialEq, Eq, Default)]
86pub struct AddPartitionsToTxnTransaction {
87 pub transactional_id: String,
88 pub producer_id: i64,
89 pub producer_epoch: i16,
90 pub verify_only: bool,
91 pub topics: Vec<super::common::add_partitions_to_txn_topic::AddPartitionsToTxnTopic>,
92 pub unknown_tagged_fields: UnknownTaggedFields,
93}
94
95impl Encode for AddPartitionsToTxnTransaction {
96 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
97 let flex = version >= 3;
98 if version >= 4 { if flex { put_compact_string(buf, &self.transactional_id) } else { put_string(buf, &self.transactional_id) } }
99 if version >= 4 { put_i64(buf, self.producer_id) }
100 if version >= 4 { put_i16(buf, self.producer_epoch) }
101 if version >= 4 { put_bool(buf, self.verify_only) }
102 if version >= 4 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
103 if flex {
104 let tagged = WriteTaggedFields::new();
105 tagged.write(buf, &self.unknown_tagged_fields);
106 }
107 Ok(())
108 }
109 fn encoded_len(&self, version: i16) -> usize {
110 let flex = version >= 3;
111 let mut n: usize = 0;
112 if version >= 4 { n += if flex { compact_string_len(&self.transactional_id) } else { string_len(&self.transactional_id) }; }
113 if version >= 4 { n += 8; }
114 if version >= 4 { n += 2; }
115 if version >= 4 { n += 1; }
116 if version >= 4 { 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 }; }
117 if flex {
118 let known_pairs: Vec<(u32, usize)> = Vec::new();
119 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
120 }
121 n
122 }
123}
124
125impl<'de> Decode<'de> for AddPartitionsToTxnTransaction {
126 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
127 let flex = version >= 3;
128 let mut out = Self::default();
129 if version >= 4 { out.transactional_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
130 if version >= 4 { out.producer_id = get_i64(buf)?; }
131 if version >= 4 { out.producer_epoch = get_i16(buf)?; }
132 if version >= 4 { out.verify_only = get_bool(buf)?; }
133 if version >= 4 { 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(super::common::add_partitions_to_txn_topic::AddPartitionsToTxnTopic::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#[must_use]
146#[allow(unused_comparisons)]
147pub fn default_json(version: i16) -> ::serde_json::Value {
148 let mut obj = ::serde_json::Map::new();
149 if version >= 4 {
150 obj.insert("transactions".to_string(), ::serde_json::Value::Array(vec![]));
151 }
152 if version <= 3 {
153 obj.insert("v3AndBelowTransactionalId".to_string(), ::serde_json::Value::String(String::new()));
154 }
155 if version <= 3 {
156 obj.insert("v3AndBelowProducerId".to_string(), ::serde_json::json!(0));
157 }
158 if version <= 3 {
159 obj.insert("v3AndBelowProducerEpoch".to_string(), ::serde_json::json!(0));
160 }
161 if version <= 3 {
162 obj.insert("v3AndBelowTopics".to_string(), ::serde_json::Value::Array(vec![]));
163 }
164 ::serde_json::Value::Object(obj)
165}
166
167impl crate::ProtocolRequest for AddPartitionsToTxnRequest {
168 const API_KEY: i16 = API_KEY;
169 const MIN_VERSION: i16 = MIN_VERSION;
170 const MAX_VERSION: i16 = MAX_VERSION;
171 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
172 type Response = super::add_partitions_to_txn_response::AddPartitionsToTxnResponse;
173}