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