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