Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionRequest.owned.rs

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