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