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