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