crabka_protocol/opt/rustwide/workdir/generated/
EndQuorumEpochResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, get_u16, put_i16, put_i32, put_u16};
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::{
11 WriteTaggedFields, encode_to_bytes, read_tagged_fields, tagged_fields_len,
12};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 54;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 1;
18pub const FLEXIBLE_MIN: i16 = 1;
19
20#[inline]
21fn is_flexible(version: i16) -> bool {
22 version >= FLEXIBLE_MIN
23}
24
25#[derive(Debug, Clone, PartialEq, Eq, Default)]
26pub struct EndQuorumEpochResponse {
27 pub error_code: i16,
28 pub topics: Vec<TopicData>,
29 pub node_endpoints: Vec<NodeEndpoint>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for EndQuorumEpochResponse {
33 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35 return Err(ProtocolError::UnsupportedVersion {
36 api_key: API_KEY,
37 version,
38 });
39 }
40 let flex = is_flexible(version);
41 if version >= 0 {
42 put_i16(buf, self.error_code);
43 }
44 if version >= 0 {
45 {
46 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
47 for it in &self.topics {
48 it.encode(buf, version)?;
49 }
50 }
51 }
52 if flex {
53 let mut tagged = WriteTaggedFields::new();
54 if !(crate::codegen_helpers::is_default(&self.node_endpoints)) {
55 let payload = encode_to_bytes(
56 {
57 let prefix = crate::primitives::array::array_len_prefix_len(
58 (self.node_endpoints).len(),
59 flex,
60 );
61 let body: usize = (self.node_endpoints)
62 .iter()
63 .map(|it| it.encoded_len(version))
64 .sum();
65 prefix + body
66 },
67 |b| {
68 {
69 crate::primitives::array::put_array_len(
70 b,
71 (self.node_endpoints).len(),
72 flex,
73 );
74 for it in &self.node_endpoints {
75 it.encode(b, version)?;
76 }
77 };
78 Ok(())
79 },
80 );
81 tagged.add(0, payload);
82 }
83 tagged.write(buf, &self.unknown_tagged_fields);
84 }
85 Ok(())
86 }
87 fn encoded_len(&self, version: i16) -> usize {
88 let flex = is_flexible(version);
89 let mut n: usize = 0;
90 if version >= 0 {
91 n += 2;
92 }
93 if version >= 0 {
94 n += {
95 let prefix =
96 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
97 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
98 prefix + body
99 };
100 }
101 if flex {
102 let mut known_pairs: Vec<(u32, usize)> = Vec::new();
103 if !(crate::codegen_helpers::is_default(&self.node_endpoints)) {
104 known_pairs.push((0, {
105 let prefix = crate::primitives::array::array_len_prefix_len(
106 (self.node_endpoints).len(),
107 flex,
108 );
109 let body: usize = (self.node_endpoints)
110 .iter()
111 .map(|it| it.encoded_len(version))
112 .sum();
113 prefix + body
114 }));
115 }
116 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
117 }
118 n
119 }
120}
121impl Decode<'_> for EndQuorumEpochResponse {
122 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
123 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
124 return Err(ProtocolError::UnsupportedVersion {
125 api_key: API_KEY,
126 version,
127 });
128 }
129 let flex = is_flexible(version);
130 let mut out = Self::default();
131 if version >= 0 {
132 out.error_code = get_i16(buf)?;
133 }
134 if version >= 0 {
135 out.topics = {
136 let n = crate::primitives::array::get_array_len(buf, flex)?;
137 let mut v = Vec::with_capacity(n);
138 for _ in 0..n {
139 v.push(TopicData::decode(buf, version)?);
140 }
141 v
142 };
143 }
144 if flex {
145 let mut tag_node_endpoints = None;
146 out.unknown_tagged_fields = read_tagged_fields(buf, |tag, payload| match tag {
147 0 => {
148 tag_node_endpoints = Some({
149 let b: &mut &[u8] = payload;
150 {
151 let n = crate::primitives::array::get_array_len(b, flex)?;
152 let mut v = Vec::with_capacity(n);
153 for _ in 0..n {
154 v.push(NodeEndpoint::decode(b, version)?);
155 }
156 v
157 }
158 });
159 Ok(true)
160 }
161 _ => Ok(false),
162 })?;
163 if let Some(v) = tag_node_endpoints {
164 out.node_endpoints = v;
165 }
166 }
167 Ok(out)
168 }
169}
170#[cfg(test)]
171impl EndQuorumEpochResponse {
172 #[must_use]
173 pub fn populated(version: i16) -> Self {
174 let mut m = Self::default();
175 if version >= 0 {
176 m.error_code = 1i16;
177 }
178 if version >= 0 {
179 m.topics = vec![TopicData::populated(version)];
180 }
181 if version >= 1 {
182 m.node_endpoints = vec![NodeEndpoint::populated(version)];
183 }
184 m
185 }
186}
187#[derive(Debug, Clone, PartialEq, Eq, Default)]
188pub struct TopicData {
189 pub topic_name: String,
190 pub partitions: Vec<PartitionData>,
191 pub unknown_tagged_fields: UnknownTaggedFields,
192}
193impl Encode for TopicData {
194 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
195 let flex = version >= 1;
196 if version >= 0 {
197 if flex {
198 put_compact_string(buf, &self.topic_name);
199 } else {
200 put_string(buf, &self.topic_name);
201 }
202 }
203 if version >= 0 {
204 {
205 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
206 for it in &self.partitions {
207 it.encode(buf, version)?;
208 }
209 }
210 }
211 if flex {
212 let tagged = WriteTaggedFields::new();
213 tagged.write(buf, &self.unknown_tagged_fields);
214 }
215 Ok(())
216 }
217 fn encoded_len(&self, version: i16) -> usize {
218 let flex = version >= 1;
219 let mut n: usize = 0;
220 if version >= 0 {
221 n += if flex {
222 compact_string_len(&self.topic_name)
223 } else {
224 string_len(&self.topic_name)
225 };
226 }
227 if version >= 0 {
228 n += {
229 let prefix =
230 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
231 let body: usize = (self.partitions)
232 .iter()
233 .map(|it| it.encoded_len(version))
234 .sum();
235 prefix + body
236 };
237 }
238 if flex {
239 let known_pairs: Vec<(u32, usize)> = Vec::new();
240 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
241 }
242 n
243 }
244}
245impl Decode<'_> for TopicData {
246 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
247 let flex = version >= 1;
248 let mut out = Self::default();
249 if version >= 0 {
250 out.topic_name = if flex {
251 get_compact_string_owned(buf)?
252 } else {
253 get_string_owned(buf)?
254 };
255 }
256 if version >= 0 {
257 out.partitions = {
258 let n = crate::primitives::array::get_array_len(buf, flex)?;
259 let mut v = Vec::with_capacity(n);
260 for _ in 0..n {
261 v.push(PartitionData::decode(buf, version)?);
262 }
263 v
264 };
265 }
266 if flex {
267 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
268 }
269 Ok(out)
270 }
271}
272#[cfg(test)]
273impl TopicData {
274 #[must_use]
275 pub fn populated(version: i16) -> Self {
276 let mut m = Self::default();
277 if version >= 0 {
278 m.topic_name = "x".to_string();
279 }
280 if version >= 0 {
281 m.partitions = vec![PartitionData::populated(version)];
282 }
283 m
284 }
285}
286#[derive(Debug, Clone, PartialEq, Eq, Default)]
287pub struct PartitionData {
288 pub partition_index: i32,
289 pub error_code: i16,
290 pub leader_id: i32,
291 pub leader_epoch: i32,
292 pub unknown_tagged_fields: UnknownTaggedFields,
293}
294impl Encode for PartitionData {
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 version >= 0 {
304 put_i32(buf, self.leader_id);
305 }
306 if version >= 0 {
307 put_i32(buf, self.leader_epoch);
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 version >= 0 {
325 n += 4;
326 }
327 if version >= 0 {
328 n += 4;
329 }
330 if flex {
331 let known_pairs: Vec<(u32, usize)> = Vec::new();
332 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
333 }
334 n
335 }
336}
337impl Decode<'_> for PartitionData {
338 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
339 let flex = version >= 1;
340 let mut out = Self::default();
341 if version >= 0 {
342 out.partition_index = get_i32(buf)?;
343 }
344 if version >= 0 {
345 out.error_code = get_i16(buf)?;
346 }
347 if version >= 0 {
348 out.leader_id = get_i32(buf)?;
349 }
350 if version >= 0 {
351 out.leader_epoch = get_i32(buf)?;
352 }
353 if flex {
354 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
355 }
356 Ok(out)
357 }
358}
359#[cfg(test)]
360impl PartitionData {
361 #[must_use]
362 pub fn populated(version: i16) -> Self {
363 let mut m = Self::default();
364 if version >= 0 {
365 m.partition_index = 1i32;
366 }
367 if version >= 0 {
368 m.error_code = 1i16;
369 }
370 if version >= 0 {
371 m.leader_id = 1i32;
372 }
373 if version >= 0 {
374 m.leader_epoch = 1i32;
375 }
376 m
377 }
378}
379#[derive(Debug, Clone, PartialEq, Eq, Default)]
380pub struct NodeEndpoint {
381 pub node_id: i32,
382 pub host: String,
383 pub port: u16,
384 pub unknown_tagged_fields: UnknownTaggedFields,
385}
386impl Encode for NodeEndpoint {
387 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
388 let flex = version >= 1;
389 if version >= 1 {
390 put_i32(buf, self.node_id);
391 }
392 if version >= 1 {
393 if flex {
394 put_compact_string(buf, &self.host);
395 } else {
396 put_string(buf, &self.host);
397 }
398 }
399 if version >= 1 {
400 put_u16(buf, self.port);
401 }
402 if flex {
403 let tagged = WriteTaggedFields::new();
404 tagged.write(buf, &self.unknown_tagged_fields);
405 }
406 Ok(())
407 }
408 fn encoded_len(&self, version: i16) -> usize {
409 let flex = version >= 1;
410 let mut n: usize = 0;
411 if version >= 1 {
412 n += 4;
413 }
414 if version >= 1 {
415 n += if flex {
416 compact_string_len(&self.host)
417 } else {
418 string_len(&self.host)
419 };
420 }
421 if version >= 1 {
422 n += 2;
423 }
424 if flex {
425 let known_pairs: Vec<(u32, usize)> = Vec::new();
426 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
427 }
428 n
429 }
430}
431impl Decode<'_> for NodeEndpoint {
432 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
433 let flex = version >= 1;
434 let mut out = Self::default();
435 if version >= 1 {
436 out.node_id = get_i32(buf)?;
437 }
438 if version >= 1 {
439 out.host = if flex {
440 get_compact_string_owned(buf)?
441 } else {
442 get_string_owned(buf)?
443 };
444 }
445 if version >= 1 {
446 out.port = get_u16(buf)?;
447 }
448 if flex {
449 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
450 }
451 Ok(out)
452 }
453}
454#[cfg(test)]
455impl NodeEndpoint {
456 #[must_use]
457 pub fn populated(version: i16) -> Self {
458 let mut m = Self::default();
459 if version >= 1 {
460 m.node_id = 1i32;
461 }
462 if version >= 1 {
463 m.host = "x".to_string();
464 }
465 if version >= 1 {
466 m.port = 1u16;
467 }
468 m
469 }
470}
471
472#[must_use]
475#[allow(unused_comparisons)]
476pub fn default_json(version: i16) -> ::serde_json::Value {
477 let mut obj = ::serde_json::Map::new();
478 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
479 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
480 if version >= 1 {
481 obj.insert(
482 "nodeEndpoints".to_string(),
483 ::serde_json::Value::Array(vec![]),
484 );
485 }
486 ::serde_json::Value::Object(obj)
487}