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