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