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