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