Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionResponse.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::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_i8, get_i16, get_i32, put_i8, put_i16, put_i32},
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 FLEXIBLE_MIN: i16 = 0;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21    version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct AlterPartitionResponse {
25    pub throttle_time_ms: i32,
26    pub error_code: i16,
27    pub topics: Vec<TopicData>,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for AlterPartitionResponse {
31    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33            return Err(ProtocolError::UnsupportedVersion {
34                api_key: API_KEY,
35                version,
36            });
37        }
38        let flex = is_flexible(version);
39        if version >= 0 {
40            put_i32(buf, self.throttle_time_ms);
41        }
42        if version >= 0 {
43            put_i16(buf, self.error_code);
44        }
45        if version >= 0 {
46            {
47                put_array_len(buf, (self.topics).len(), flex)?;
48                for it in &self.topics {
49                    it.encode(buf, version)?;
50                }
51            }
52        }
53        if flex {
54            let tagged = WriteTaggedFields::new();
55            tagged.write(buf, &self.unknown_tagged_fields)?;
56        }
57        Ok(())
58    }
59    fn encoded_len(&self, version: i16) -> usize {
60        let flex = is_flexible(version);
61        let mut n: usize = 0;
62        if version >= 0 {
63            n += 4;
64        }
65        if version >= 0 {
66            n += 2;
67        }
68        if version >= 0 {
69            n += {
70                let prefix = array_len_prefix_len((self.topics).len(), flex);
71                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
72                prefix + body
73            };
74        }
75        if flex {
76            let known_pairs: Vec<(u32, usize)> = Vec::new();
77            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
78        }
79        n
80    }
81}
82impl Decode<'_> for AlterPartitionResponse {
83    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
84        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
85            return Err(ProtocolError::UnsupportedVersion {
86                api_key: API_KEY,
87                version,
88            });
89        }
90        let flex = is_flexible(version);
91        let mut out = Self::default();
92        if version >= 0 {
93            out.throttle_time_ms = get_i32(buf)?;
94        }
95        if version >= 0 {
96            out.error_code = get_i16(buf)?;
97        }
98        if version >= 0 {
99            out.topics = {
100                let n = get_array_len(buf, flex)?;
101                let mut v = Vec::with_capacity(n);
102                for _ in 0..n {
103                    v.push(TopicData::decode(buf, version)?);
104                }
105                v
106            };
107        }
108        if flex {
109            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
110        }
111        Ok(out)
112    }
113}
114#[cfg(test)]
115impl AlterPartitionResponse {
116    #[must_use]
117    pub fn populated(version: i16) -> Self {
118        let mut m = Self::default();
119        if version >= 0 {
120            m.throttle_time_ms = 1i32;
121        }
122        if version >= 0 {
123            m.error_code = 1i16;
124        }
125        if version >= 0 {
126            m.topics = vec![TopicData::populated(version)];
127        }
128        m
129    }
130}
131#[derive(Debug, Clone, PartialEq, Eq, Default)]
132pub struct TopicData {
133    pub topic_id: Uuid,
134    pub partitions: Vec<PartitionData>,
135    pub unknown_tagged_fields: UnknownTaggedFields,
136}
137impl Encode for TopicData {
138    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
139        let flex = version >= 0;
140        if version >= 2 {
141            put_uuid(buf, self.topic_id);
142        }
143        if version >= 0 {
144            {
145                put_array_len(buf, (self.partitions).len(), flex)?;
146                for it in &self.partitions {
147                    it.encode(buf, version)?;
148                }
149            }
150        }
151        if flex {
152            let tagged = WriteTaggedFields::new();
153            tagged.write(buf, &self.unknown_tagged_fields)?;
154        }
155        Ok(())
156    }
157    fn encoded_len(&self, version: i16) -> usize {
158        let flex = version >= 0;
159        let mut n: usize = 0;
160        if version >= 2 {
161            n += 16;
162        }
163        if version >= 0 {
164            n += {
165                let prefix = array_len_prefix_len((self.partitions).len(), flex);
166                let body: usize = (self.partitions)
167                    .iter()
168                    .map(|it| it.encoded_len(version))
169                    .sum();
170                prefix + body
171            };
172        }
173        if flex {
174            let known_pairs: Vec<(u32, usize)> = Vec::new();
175            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
176        }
177        n
178    }
179}
180impl Decode<'_> for TopicData {
181    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
182        let flex = version >= 0;
183        let mut out = Self::default();
184        if version >= 2 {
185            out.topic_id = get_uuid(buf)?;
186        }
187        if version >= 0 {
188            out.partitions = {
189                let n = get_array_len(buf, flex)?;
190                let mut v = Vec::with_capacity(n);
191                for _ in 0..n {
192                    v.push(PartitionData::decode(buf, version)?);
193                }
194                v
195            };
196        }
197        if flex {
198            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
199        }
200        Ok(out)
201    }
202}
203#[cfg(test)]
204impl TopicData {
205    #[must_use]
206    pub fn populated(version: i16) -> Self {
207        let mut m = Self::default();
208        if version >= 2 {
209            m.topic_id = Uuid([1u8; 16]);
210        }
211        if version >= 0 {
212            m.partitions = vec![PartitionData::populated(version)];
213        }
214        m
215    }
216}
217#[derive(Debug, Clone, PartialEq, Eq, Default)]
218pub struct PartitionData {
219    pub partition_index: i32,
220    pub error_code: i16,
221    pub leader_id: i32,
222    pub leader_epoch: i32,
223    pub isr: Vec<i32>,
224    pub leader_recovery_state: i8,
225    pub partition_epoch: i32,
226    pub unknown_tagged_fields: UnknownTaggedFields,
227}
228impl Encode for PartitionData {
229    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
230        let flex = version >= 0;
231        if version >= 0 {
232            put_i32(buf, self.partition_index);
233        }
234        if version >= 0 {
235            put_i16(buf, self.error_code);
236        }
237        if version >= 0 {
238            put_i32(buf, self.leader_id);
239        }
240        if version >= 0 {
241            put_i32(buf, self.leader_epoch);
242        }
243        if version >= 0 {
244            {
245                put_array_len(buf, (self.isr).len(), flex)?;
246                for it in &self.isr {
247                    put_i32(buf, *it);
248                }
249            }
250        }
251        if version >= 1 {
252            put_i8(buf, self.leader_recovery_state);
253        }
254        if version >= 0 {
255            put_i32(buf, self.partition_epoch);
256        }
257        if flex {
258            let tagged = WriteTaggedFields::new();
259            tagged.write(buf, &self.unknown_tagged_fields)?;
260        }
261        Ok(())
262    }
263    fn encoded_len(&self, version: i16) -> usize {
264        let flex = version >= 0;
265        let mut n: usize = 0;
266        if version >= 0 {
267            n += 4;
268        }
269        if version >= 0 {
270            n += 2;
271        }
272        if version >= 0 {
273            n += 4;
274        }
275        if version >= 0 {
276            n += 4;
277        }
278        if version >= 0 {
279            n += {
280                let prefix = array_len_prefix_len((self.isr).len(), flex);
281                let body: usize = (self.isr).iter().map(|_| 4).sum();
282                prefix + body
283            };
284        }
285        if version >= 1 {
286            n += 1;
287        }
288        if version >= 0 {
289            n += 4;
290        }
291        if flex {
292            let known_pairs: Vec<(u32, usize)> = Vec::new();
293            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
294        }
295        n
296    }
297}
298impl Decode<'_> for PartitionData {
299    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
300        let flex = version >= 0;
301        let mut out = Self::default();
302        if version >= 0 {
303            out.partition_index = get_i32(buf)?;
304        }
305        if version >= 0 {
306            out.error_code = get_i16(buf)?;
307        }
308        if version >= 0 {
309            out.leader_id = get_i32(buf)?;
310        }
311        if version >= 0 {
312            out.leader_epoch = get_i32(buf)?;
313        }
314        if version >= 0 {
315            out.isr = {
316                let n = get_array_len(buf, flex)?;
317                let mut v = Vec::with_capacity(n);
318                for _ in 0..n {
319                    v.push(get_i32(buf)?);
320                }
321                v
322            };
323        }
324        if version >= 1 {
325            out.leader_recovery_state = get_i8(buf)?;
326        }
327        if version >= 0 {
328            out.partition_epoch = get_i32(buf)?;
329        }
330        if flex {
331            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
332        }
333        Ok(out)
334    }
335}
336#[cfg(test)]
337impl PartitionData {
338    #[must_use]
339    pub fn populated(version: i16) -> Self {
340        let mut m = Self::default();
341        if version >= 0 {
342            m.partition_index = 1i32;
343        }
344        if version >= 0 {
345            m.error_code = 1i16;
346        }
347        if version >= 0 {
348            m.leader_id = 1i32;
349        }
350        if version >= 0 {
351            m.leader_epoch = 1i32;
352        }
353        if version >= 0 {
354            m.isr = vec![1i32];
355        }
356        if version >= 1 {
357            m.leader_recovery_state = 1i8;
358        }
359        if version >= 0 {
360            m.partition_epoch = 1i32;
361        }
362        m
363    }
364}
365/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
366/// Only includes fields valid for the given version.
367#[must_use]
368#[allow(unused_comparisons)]
369pub fn default_json(_version: i16) -> ::serde_json::Value {
370    let mut obj = ::serde_json::Map::new();
371    obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
372    obj.insert("errorCode".to_owned(), ::serde_json::json!(0));
373    obj.insert("topics".to_owned(), ::serde_json::Value::Array(vec![]));
374    ::serde_json::Value::Object(obj)
375}