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