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