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