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