Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
8    string_len,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 46;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const FLEXIBLE_MIN: i16 = 0;
17
18#[inline]
19fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct ListPartitionReassignmentsRequest {
25    pub timeout_ms: i32,
26    pub topics: Option<Vec<ListPartitionReassignmentsTopics>>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl Default for ListPartitionReassignmentsRequest {
30    fn default() -> Self {
31        Self {
32            timeout_ms: 60_000i32,
33            topics: None,
34            unknown_tagged_fields: Default::default(),
35        }
36    }
37}
38impl Encode for ListPartitionReassignmentsRequest {
39    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
40        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
41            return Err(ProtocolError::UnsupportedVersion {
42                api_key: API_KEY,
43                version,
44            });
45        }
46        let flex = is_flexible(version);
47        if version >= 0 {
48            put_i32(buf, self.timeout_ms);
49        }
50        if version >= 0 {
51            {
52                let len = (self.topics).as_ref().map(Vec::len);
53                crate::primitives::array::put_nullable_array_len(buf, len, flex);
54                if let Some(v) = &self.topics {
55                    for it in v {
56                        it.encode(buf, version)?;
57                    }
58                }
59            }
60        }
61        if flex {
62            let tagged = WriteTaggedFields::new();
63            tagged.write(buf, &self.unknown_tagged_fields);
64        }
65        Ok(())
66    }
67    fn encoded_len(&self, version: i16) -> usize {
68        let flex = is_flexible(version);
69        let mut n: usize = 0;
70        if version >= 0 {
71            n += 4;
72        }
73        if version >= 0 {
74            n += {
75                let opt: Option<&Vec<_>> = (self.topics).as_ref();
76                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
77                    opt.map(std::vec::Vec::len),
78                    flex,
79                );
80                let body: usize =
81                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
82                prefix + body
83            };
84        }
85        if flex {
86            let known_pairs: Vec<(u32, usize)> = Vec::new();
87            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
88        }
89        n
90    }
91}
92impl Decode<'_> for ListPartitionReassignmentsRequest {
93    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
94        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
95            return Err(ProtocolError::UnsupportedVersion {
96                api_key: API_KEY,
97                version,
98            });
99        }
100        let flex = is_flexible(version);
101        let mut out = Self::default();
102        if version >= 0 {
103            out.timeout_ms = get_i32(buf)?;
104        }
105        if version >= 0 {
106            out.topics = {
107                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
108                match opt {
109                    None => None,
110                    Some(n) => {
111                        let mut v = Vec::with_capacity(n);
112                        for _ in 0..n {
113                            v.push(ListPartitionReassignmentsTopics::decode(buf, version)?);
114                        }
115                        Some(v)
116                    }
117                }
118            };
119        }
120        if flex {
121            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
122        }
123        Ok(out)
124    }
125}
126#[cfg(test)]
127impl ListPartitionReassignmentsRequest {
128    #[must_use]
129    pub fn populated(version: i16) -> Self {
130        let mut m = Self::default();
131        if version >= 0 {
132            m.timeout_ms = 1i32;
133        }
134        if version >= 0 {
135            m.topics = Some(vec![ListPartitionReassignmentsTopics::populated(version)]);
136        }
137        m
138    }
139}
140#[derive(Debug, Clone, PartialEq, Eq, Default)]
141pub struct ListPartitionReassignmentsTopics {
142    pub name: String,
143    pub partition_indexes: Vec<i32>,
144    pub unknown_tagged_fields: UnknownTaggedFields,
145}
146impl Encode for ListPartitionReassignmentsTopics {
147    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
148        let flex = version >= 0;
149        if version >= 0 {
150            if flex {
151                put_compact_string(buf, &self.name);
152            } else {
153                put_string(buf, &self.name);
154            }
155        }
156        if version >= 0 {
157            {
158                crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex);
159                for it in &self.partition_indexes {
160                    put_i32(buf, *it);
161                }
162            }
163        }
164        if flex {
165            let tagged = WriteTaggedFields::new();
166            tagged.write(buf, &self.unknown_tagged_fields);
167        }
168        Ok(())
169    }
170    fn encoded_len(&self, version: i16) -> usize {
171        let flex = version >= 0;
172        let mut n: usize = 0;
173        if version >= 0 {
174            n += if flex {
175                compact_string_len(&self.name)
176            } else {
177                string_len(&self.name)
178            };
179        }
180        if version >= 0 {
181            n += {
182                let prefix = crate::primitives::array::array_len_prefix_len(
183                    (self.partition_indexes).len(),
184                    flex,
185                );
186                let body: usize = (self.partition_indexes).iter().map(|_| 4).sum();
187                prefix + body
188            };
189        }
190        if flex {
191            let known_pairs: Vec<(u32, usize)> = Vec::new();
192            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
193        }
194        n
195    }
196}
197impl Decode<'_> for ListPartitionReassignmentsTopics {
198    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
199        let flex = version >= 0;
200        let mut out = Self::default();
201        if version >= 0 {
202            out.name = if flex {
203                get_compact_string_owned(buf)?
204            } else {
205                get_string_owned(buf)?
206            };
207        }
208        if version >= 0 {
209            out.partition_indexes = {
210                let n = crate::primitives::array::get_array_len(buf, flex)?;
211                let mut v = Vec::with_capacity(n);
212                for _ in 0..n {
213                    v.push(get_i32(buf)?);
214                }
215                v
216            };
217        }
218        if flex {
219            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
220        }
221        Ok(out)
222    }
223}
224#[cfg(test)]
225impl ListPartitionReassignmentsTopics {
226    #[must_use]
227    pub fn populated(version: i16) -> Self {
228        let mut m = Self::default();
229        if version >= 0 {
230            m.name = "x".to_string();
231        }
232        if version >= 0 {
233            m.partition_indexes = vec![1i32];
234        }
235        m
236    }
237}
238
239/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
240/// Only includes fields valid for the given version.
241#[must_use]
242#[allow(unused_comparisons)]
243pub fn default_json(version: i16) -> ::serde_json::Value {
244    let mut obj = ::serde_json::Map::new();
245    obj.insert("timeoutMs".to_string(), ::serde_json::json!(60000));
246    obj.insert("topics".to_string(), ::serde_json::Value::Null);
247    ::serde_json::Value::Object(obj)
248}
249
250impl crate::ProtocolRequest for ListPartitionReassignmentsRequest {
251    const API_KEY: i16 = API_KEY;
252    const MIN_VERSION: i16 = MIN_VERSION;
253    const MAX_VERSION: i16 = MAX_VERSION;
254    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
255    type Response =
256        super::list_partition_reassignments_response::ListPartitionReassignmentsResponse;
257}