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