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