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