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