Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionResponse.owned.rs

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