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