crabka_protocol/opt/rustwide/workdir/generated/
AddPartitionsToTxnResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
8 string_len,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
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 {
20 version >= FLEXIBLE_MIN
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct AddPartitionsToTxnResponse { pub throttle_time_ms : i32 , pub error_code : i16 , pub results_by_transaction : Vec < AddPartitionsToTxnResult > , pub results_by_topic_v3_and_below : Vec < super :: common :: add_partitions_to_txn_response :: add_partitions_to_txn_topic_result :: AddPartitionsToTxnTopicResult > , pub unknown_tagged_fields : UnknownTaggedFields , }
25impl Encode for AddPartitionsToTxnResponse {
26 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
27 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
28 return Err(ProtocolError::UnsupportedVersion {
29 api_key: API_KEY,
30 version,
31 });
32 }
33 let flex = is_flexible(version);
34 if version >= 0 {
35 put_i32(buf, self.throttle_time_ms);
36 }
37 if version >= 4 {
38 put_i16(buf, self.error_code);
39 }
40 if version >= 4 {
41 {
42 crate::primitives::array::put_array_len(
43 buf,
44 (self.results_by_transaction).len(),
45 flex,
46 );
47 for it in &self.results_by_transaction {
48 it.encode(buf, version)?;
49 }
50 }
51 }
52 if (0..=3).contains(&version) {
53 {
54 crate::primitives::array::put_array_len(
55 buf,
56 (self.results_by_topic_v3_and_below).len(),
57 flex,
58 );
59 for it in &self.results_by_topic_v3_and_below {
60 it.encode(buf, version)?;
61 }
62 }
63 }
64 if flex {
65 let tagged = WriteTaggedFields::new();
66 tagged.write(buf, &self.unknown_tagged_fields);
67 }
68 Ok(())
69 }
70 fn encoded_len(&self, version: i16) -> usize {
71 let flex = is_flexible(version);
72 let mut n: usize = 0;
73 if version >= 0 {
74 n += 4;
75 }
76 if version >= 4 {
77 n += 2;
78 }
79 if version >= 4 {
80 n += {
81 let prefix = crate::primitives::array::array_len_prefix_len(
82 (self.results_by_transaction).len(),
83 flex,
84 );
85 let body: usize = (self.results_by_transaction)
86 .iter()
87 .map(|it| it.encoded_len(version))
88 .sum();
89 prefix + body
90 };
91 }
92 if (0..=3).contains(&version) {
93 n += {
94 let prefix = crate::primitives::array::array_len_prefix_len(
95 (self.results_by_topic_v3_and_below).len(),
96 flex,
97 );
98 let body: usize = (self.results_by_topic_v3_and_below)
99 .iter()
100 .map(|it| it.encoded_len(version))
101 .sum();
102 prefix + body
103 };
104 }
105 if flex {
106 let known_pairs: Vec<(u32, usize)> = Vec::new();
107 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
108 }
109 n
110 }
111}
112impl Decode<'_> for AddPartitionsToTxnResponse {
113 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
114 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
115 return Err(ProtocolError::UnsupportedVersion {
116 api_key: API_KEY,
117 version,
118 });
119 }
120 let flex = is_flexible(version);
121 let mut out = Self::default();
122 if version >= 0 {
123 out.throttle_time_ms = get_i32(buf)?;
124 }
125 if version >= 4 {
126 out.error_code = get_i16(buf)?;
127 }
128 if version >= 4 {
129 out.results_by_transaction = {
130 let n = crate::primitives::array::get_array_len(buf, flex)?;
131 let mut v = Vec::with_capacity(n);
132 for _ in 0..n {
133 v.push(AddPartitionsToTxnResult::decode(buf, version)?);
134 }
135 v
136 };
137 }
138 if (0..=3).contains(&version) {
139 out.results_by_topic_v3_and_below = {
140 let n = crate::primitives::array::get_array_len(buf, flex)?;
141 let mut v = Vec::with_capacity(n);
142 for _ in 0..n {
143 v . push (super :: common :: add_partitions_to_txn_response :: add_partitions_to_txn_topic_result :: AddPartitionsToTxnTopicResult :: decode (buf , version) ?) ;
144 }
145 v
146 };
147 }
148 if flex {
149 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
150 }
151 Ok(out)
152 }
153}
154#[cfg(test)]
155impl AddPartitionsToTxnResponse {
156 #[must_use]
157 pub fn populated(version: i16) -> Self {
158 let mut m = Self::default();
159 if version >= 0 {
160 m.throttle_time_ms = 1i32;
161 }
162 if version >= 4 {
163 m.error_code = 1i16;
164 }
165 if version >= 4 {
166 m.results_by_transaction = vec![AddPartitionsToTxnResult::populated(version)];
167 }
168 if (0..=3).contains(&version) {
169 m . results_by_topic_v3_and_below = vec ! [super :: common :: add_partitions_to_txn_response :: add_partitions_to_txn_topic_result :: AddPartitionsToTxnTopicResult :: populated (version)] ;
170 }
171 m
172 }
173}
174#[derive(Debug, Clone, PartialEq, Eq, Default)]
175pub struct AddPartitionsToTxnResult { pub transactional_id : String , pub topic_results : Vec < super :: common :: add_partitions_to_txn_response :: add_partitions_to_txn_topic_result :: AddPartitionsToTxnTopicResult > , pub unknown_tagged_fields : UnknownTaggedFields , }
176impl Encode for AddPartitionsToTxnResult {
177 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
178 let flex = version >= 3;
179 if version >= 4 {
180 if flex {
181 put_compact_string(buf, &self.transactional_id);
182 } else {
183 put_string(buf, &self.transactional_id);
184 }
185 }
186 if version >= 4 {
187 {
188 crate::primitives::array::put_array_len(buf, (self.topic_results).len(), flex);
189 for it in &self.topic_results {
190 it.encode(buf, version)?;
191 }
192 }
193 }
194 if flex {
195 let tagged = WriteTaggedFields::new();
196 tagged.write(buf, &self.unknown_tagged_fields);
197 }
198 Ok(())
199 }
200 fn encoded_len(&self, version: i16) -> usize {
201 let flex = version >= 3;
202 let mut n: usize = 0;
203 if version >= 4 {
204 n += if flex {
205 compact_string_len(&self.transactional_id)
206 } else {
207 string_len(&self.transactional_id)
208 };
209 }
210 if version >= 4 {
211 n += {
212 let prefix = crate::primitives::array::array_len_prefix_len(
213 (self.topic_results).len(),
214 flex,
215 );
216 let body: usize = (self.topic_results)
217 .iter()
218 .map(|it| it.encoded_len(version))
219 .sum();
220 prefix + body
221 };
222 }
223 if flex {
224 let known_pairs: Vec<(u32, usize)> = Vec::new();
225 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
226 }
227 n
228 }
229}
230impl Decode<'_> for AddPartitionsToTxnResult {
231 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
232 let flex = version >= 3;
233 let mut out = Self::default();
234 if version >= 4 {
235 out.transactional_id = if flex {
236 get_compact_string_owned(buf)?
237 } else {
238 get_string_owned(buf)?
239 };
240 }
241 if version >= 4 {
242 out.topic_results = {
243 let n = crate::primitives::array::get_array_len(buf, flex)?;
244 let mut v = Vec::with_capacity(n);
245 for _ in 0..n {
246 v . push (super :: common :: add_partitions_to_txn_response :: add_partitions_to_txn_topic_result :: AddPartitionsToTxnTopicResult :: decode (buf , version) ?) ;
247 }
248 v
249 };
250 }
251 if flex {
252 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
253 }
254 Ok(out)
255 }
256}
257#[cfg(test)]
258impl AddPartitionsToTxnResult {
259 #[must_use]
260 pub fn populated(version: i16) -> Self {
261 let mut m = Self::default();
262 if version >= 4 {
263 m.transactional_id = "x".to_string();
264 }
265 if version >= 4 {
266 m . topic_results = vec ! [super :: common :: add_partitions_to_txn_response :: add_partitions_to_txn_topic_result :: AddPartitionsToTxnTopicResult :: populated (version)] ;
267 }
268 m
269 }
270}
271
272#[must_use]
275#[allow(unused_comparisons)]
276pub fn default_json(version: i16) -> ::serde_json::Value {
277 let mut obj = ::serde_json::Map::new();
278 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
279 if version >= 4 {
280 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
281 }
282 if version >= 4 {
283 obj.insert(
284 "resultsByTransaction".to_string(),
285 ::serde_json::Value::Array(vec![]),
286 );
287 }
288 if version <= 3 {
289 obj.insert(
290 "resultsByTopicV3AndBelow".to_string(),
291 ::serde_json::Value::Array(vec![]),
292 );
293 }
294 ::serde_json::Value::Object(obj)
295}