Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_bool, get_i32, put_bool, put_i32};
4use crate::primitives::string_bytes::{
5    compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
6    string_len,
7};
8use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
9use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
10use bytes::{Buf, BufMut};
11pub const API_KEY: i16 = 45;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 1;
14pub const FLEXIBLE_MIN: i16 = 0;
15#[inline]
16fn is_flexible(version: i16) -> bool {
17    version >= FLEXIBLE_MIN
18}
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct AlterPartitionReassignmentsRequest {
21    pub timeout_ms: i32,
22    pub allow_replication_factor_change: bool,
23    pub topics: Vec<ReassignableTopic>,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Default for AlterPartitionReassignmentsRequest {
27    fn default() -> Self {
28        Self {
29            timeout_ms: 60_000i32,
30            allow_replication_factor_change: true,
31            topics: Vec::new(),
32            unknown_tagged_fields: Default::default(),
33        }
34    }
35}
36impl Encode for AlterPartitionReassignmentsRequest {
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.timeout_ms);
47        }
48        if version >= 1 {
49            put_bool(buf, self.allow_replication_factor_change);
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 >= 1 {
72            n += 1;
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 AlterPartitionReassignmentsRequest {
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.timeout_ms = get_i32(buf)?;
101        }
102        if version >= 1 {
103            out.allow_replication_factor_change = get_bool(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(ReassignableTopic::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 AlterPartitionReassignmentsRequest {
123    #[must_use]
124    pub fn populated(version: i16) -> Self {
125        let mut m = Self::default();
126        if version >= 0 {
127            m.timeout_ms = 1i32;
128        }
129        if version >= 1 {
130            m.allow_replication_factor_change = true;
131        }
132        if version >= 0 {
133            m.topics = vec![ReassignableTopic::populated(version)];
134        }
135        m
136    }
137}
138#[derive(Debug, Clone, PartialEq, Eq, Default)]
139pub struct ReassignableTopic {
140    pub name: String,
141    pub partitions: Vec<ReassignablePartition>,
142    pub unknown_tagged_fields: UnknownTaggedFields,
143}
144impl Encode for ReassignableTopic {
145    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
146        let flex = version >= 0;
147        if version >= 0 {
148            if flex {
149                put_compact_string(buf, &self.name);
150            } else {
151                put_string(buf, &self.name);
152            }
153        }
154        if version >= 0 {
155            {
156                crate::primitives::array::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 >= 0 {
172            n += if flex {
173                compact_string_len(&self.name)
174            } else {
175                string_len(&self.name)
176            };
177        }
178        if version >= 0 {
179            n += {
180                let prefix =
181                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
182                let body: usize = (self.partitions)
183                    .iter()
184                    .map(|it| it.encoded_len(version))
185                    .sum();
186                prefix + body
187            };
188        }
189        if flex {
190            let known_pairs: Vec<(u32, usize)> = Vec::new();
191            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
192        }
193        n
194    }
195}
196impl Decode<'_> for ReassignableTopic {
197    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
198        let flex = version >= 0;
199        let mut out = Self::default();
200        if version >= 0 {
201            out.name = if flex {
202                get_compact_string_owned(buf)?
203            } else {
204                get_string_owned(buf)?
205            };
206        }
207        if version >= 0 {
208            out.partitions = {
209                let n = crate::primitives::array::get_array_len(buf, flex)?;
210                let mut v = Vec::with_capacity(n);
211                for _ in 0..n {
212                    v.push(ReassignablePartition::decode(buf, version)?);
213                }
214                v
215            };
216        }
217        if flex {
218            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
219        }
220        Ok(out)
221    }
222}
223#[cfg(test)]
224impl ReassignableTopic {
225    #[must_use]
226    pub fn populated(version: i16) -> Self {
227        let mut m = Self::default();
228        if version >= 0 {
229            m.name = "x".to_string();
230        }
231        if version >= 0 {
232            m.partitions = vec![ReassignablePartition::populated(version)];
233        }
234        m
235    }
236}
237#[derive(Debug, Clone, PartialEq, Eq, Default)]
238pub struct ReassignablePartition {
239    pub partition_index: i32,
240    pub replicas: Option<Vec<i32>>,
241    pub unknown_tagged_fields: UnknownTaggedFields,
242}
243impl Encode for ReassignablePartition {
244    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
245        let flex = version >= 0;
246        if version >= 0 {
247            put_i32(buf, self.partition_index);
248        }
249        if version >= 0 {
250            {
251                let len = (self.replicas).as_ref().map(Vec::len);
252                crate::primitives::array::put_nullable_array_len(buf, len, flex);
253                if let Some(v) = &self.replicas {
254                    for it in v {
255                        put_i32(buf, *it);
256                    }
257                }
258            }
259        }
260        if flex {
261            let tagged = WriteTaggedFields::new();
262            tagged.write(buf, &self.unknown_tagged_fields);
263        }
264        Ok(())
265    }
266    fn encoded_len(&self, version: i16) -> usize {
267        let flex = version >= 0;
268        let mut n: usize = 0;
269        if version >= 0 {
270            n += 4;
271        }
272        if version >= 0 {
273            n += {
274                let opt: Option<&Vec<_>> = (self.replicas).as_ref();
275                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
276                    opt.map(std::vec::Vec::len),
277                    flex,
278                );
279                let body: usize = opt.map_or(0, |v| v.iter().map(|_| 4).sum());
280                prefix + body
281            };
282        }
283        if flex {
284            let known_pairs: Vec<(u32, usize)> = Vec::new();
285            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
286        }
287        n
288    }
289}
290impl Decode<'_> for ReassignablePartition {
291    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
292        let flex = version >= 0;
293        let mut out = Self::default();
294        if version >= 0 {
295            out.partition_index = get_i32(buf)?;
296        }
297        if version >= 0 {
298            out.replicas = {
299                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
300                match opt {
301                    None => None,
302                    Some(n) => {
303                        let mut v = Vec::with_capacity(n);
304                        for _ in 0..n {
305                            v.push(get_i32(buf)?);
306                        }
307                        Some(v)
308                    }
309                }
310            };
311        }
312        if flex {
313            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
314        }
315        Ok(out)
316    }
317}
318#[cfg(test)]
319impl ReassignablePartition {
320    #[must_use]
321    pub fn populated(version: i16) -> Self {
322        let mut m = Self::default();
323        if version >= 0 {
324            m.partition_index = 1i32;
325        }
326        if version >= 0 {
327            m.replicas = Some(vec![1i32]);
328        }
329        m
330    }
331}
332/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
333/// Only includes fields valid for the given version.
334#[must_use]
335#[allow(unused_comparisons)]
336pub fn default_json(version: i16) -> ::serde_json::Value {
337    let mut obj = ::serde_json::Map::new();
338    obj.insert("timeoutMs".to_string(), ::serde_json::json!(60000));
339    if version >= 1 {
340        obj.insert(
341            "allowReplicationFactorChange".to_string(),
342            ::serde_json::Value::Bool(true),
343        );
344    }
345    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
346    ::serde_json::Value::Object(obj)
347}
348impl crate::ProtocolRequest for AlterPartitionReassignmentsRequest {
349    const API_KEY: i16 = API_KEY;
350    const MIN_VERSION: i16 = MIN_VERSION;
351    const MAX_VERSION: i16 = MAX_VERSION;
352    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
353    type Response =
354        super::alter_partition_reassignments_response::AlterPartitionReassignmentsResponse;
355}