crabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionReassignmentsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i32, put_bool, 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 = 45;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 1;
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 AlterPartitionReassignmentsRequest {
25 pub timeout_ms: i32,
26 pub allow_replication_factor_change: bool,
27 pub topics: Vec<ReassignableTopic>,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Default for AlterPartitionReassignmentsRequest {
31 fn default() -> Self {
32 Self {
33 timeout_ms: 60_000i32,
34 allow_replication_factor_change: true,
35 topics: Vec::new(),
36 unknown_tagged_fields: Default::default(),
37 }
38 }
39}
40impl Encode for AlterPartitionReassignmentsRequest {
41 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
42 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
43 return Err(ProtocolError::UnsupportedVersion {
44 api_key: API_KEY,
45 version,
46 });
47 }
48 let flex = is_flexible(version);
49 if version >= 0 {
50 put_i32(buf, self.timeout_ms);
51 }
52 if version >= 1 {
53 put_bool(buf, self.allow_replication_factor_change);
54 }
55 if version >= 0 {
56 {
57 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
58 for it in &self.topics {
59 it.encode(buf, version)?;
60 }
61 }
62 }
63 if flex {
64 let tagged = WriteTaggedFields::new();
65 tagged.write(buf, &self.unknown_tagged_fields);
66 }
67 Ok(())
68 }
69 fn encoded_len(&self, version: i16) -> usize {
70 let flex = is_flexible(version);
71 let mut n: usize = 0;
72 if version >= 0 {
73 n += 4;
74 }
75 if version >= 1 {
76 n += 1;
77 }
78 if version >= 0 {
79 n += {
80 let prefix =
81 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
82 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
83 prefix + body
84 };
85 }
86 if flex {
87 let known_pairs: Vec<(u32, usize)> = Vec::new();
88 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
89 }
90 n
91 }
92}
93impl Decode<'_> for AlterPartitionReassignmentsRequest {
94 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
95 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
96 return Err(ProtocolError::UnsupportedVersion {
97 api_key: API_KEY,
98 version,
99 });
100 }
101 let flex = is_flexible(version);
102 let mut out = Self::default();
103 if version >= 0 {
104 out.timeout_ms = get_i32(buf)?;
105 }
106 if version >= 1 {
107 out.allow_replication_factor_change = get_bool(buf)?;
108 }
109 if version >= 0 {
110 out.topics = {
111 let n = crate::primitives::array::get_array_len(buf, flex)?;
112 let mut v = Vec::with_capacity(n);
113 for _ in 0..n {
114 v.push(ReassignableTopic::decode(buf, version)?);
115 }
116 v
117 };
118 }
119 if flex {
120 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
121 }
122 Ok(out)
123 }
124}
125#[cfg(test)]
126impl AlterPartitionReassignmentsRequest {
127 #[must_use]
128 pub fn populated(version: i16) -> Self {
129 let mut m = Self::default();
130 if version >= 0 {
131 m.timeout_ms = 1i32;
132 }
133 if version >= 1 {
134 m.allow_replication_factor_change = true;
135 }
136 if version >= 0 {
137 m.topics = vec![ReassignableTopic::populated(version)];
138 }
139 m
140 }
141}
142#[derive(Debug, Clone, PartialEq, Eq, Default)]
143pub struct ReassignableTopic {
144 pub name: String,
145 pub partitions: Vec<ReassignablePartition>,
146 pub unknown_tagged_fields: UnknownTaggedFields,
147}
148impl Encode for ReassignableTopic {
149 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
150 let flex = version >= 0;
151 if version >= 0 {
152 if flex {
153 put_compact_string(buf, &self.name);
154 } else {
155 put_string(buf, &self.name);
156 }
157 }
158 if version >= 0 {
159 {
160 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
161 for it in &self.partitions {
162 it.encode(buf, version)?;
163 }
164 }
165 }
166 if flex {
167 let tagged = WriteTaggedFields::new();
168 tagged.write(buf, &self.unknown_tagged_fields);
169 }
170 Ok(())
171 }
172 fn encoded_len(&self, version: i16) -> usize {
173 let flex = version >= 0;
174 let mut n: usize = 0;
175 if version >= 0 {
176 n += if flex {
177 compact_string_len(&self.name)
178 } else {
179 string_len(&self.name)
180 };
181 }
182 if version >= 0 {
183 n += {
184 let prefix =
185 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
186 let body: usize = (self.partitions)
187 .iter()
188 .map(|it| it.encoded_len(version))
189 .sum();
190 prefix + body
191 };
192 }
193 if flex {
194 let known_pairs: Vec<(u32, usize)> = Vec::new();
195 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
196 }
197 n
198 }
199}
200impl Decode<'_> for ReassignableTopic {
201 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
202 let flex = version >= 0;
203 let mut out = Self::default();
204 if version >= 0 {
205 out.name = if flex {
206 get_compact_string_owned(buf)?
207 } else {
208 get_string_owned(buf)?
209 };
210 }
211 if version >= 0 {
212 out.partitions = {
213 let n = crate::primitives::array::get_array_len(buf, flex)?;
214 let mut v = Vec::with_capacity(n);
215 for _ in 0..n {
216 v.push(ReassignablePartition::decode(buf, version)?);
217 }
218 v
219 };
220 }
221 if flex {
222 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
223 }
224 Ok(out)
225 }
226}
227#[cfg(test)]
228impl ReassignableTopic {
229 #[must_use]
230 pub fn populated(version: i16) -> Self {
231 let mut m = Self::default();
232 if version >= 0 {
233 m.name = "x".to_string();
234 }
235 if version >= 0 {
236 m.partitions = vec![ReassignablePartition::populated(version)];
237 }
238 m
239 }
240}
241#[derive(Debug, Clone, PartialEq, Eq, Default)]
242pub struct ReassignablePartition {
243 pub partition_index: i32,
244 pub replicas: Option<Vec<i32>>,
245 pub unknown_tagged_fields: UnknownTaggedFields,
246}
247impl Encode for ReassignablePartition {
248 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
249 let flex = version >= 0;
250 if version >= 0 {
251 put_i32(buf, self.partition_index);
252 }
253 if version >= 0 {
254 {
255 let len = (self.replicas).as_ref().map(Vec::len);
256 crate::primitives::array::put_nullable_array_len(buf, len, flex);
257 if let Some(v) = &self.replicas {
258 for it in v {
259 put_i32(buf, *it);
260 }
261 }
262 }
263 }
264 if flex {
265 let tagged = WriteTaggedFields::new();
266 tagged.write(buf, &self.unknown_tagged_fields);
267 }
268 Ok(())
269 }
270 fn encoded_len(&self, version: i16) -> usize {
271 let flex = version >= 0;
272 let mut n: usize = 0;
273 if version >= 0 {
274 n += 4;
275 }
276 if version >= 0 {
277 n += {
278 let opt: Option<&Vec<_>> = (self.replicas).as_ref();
279 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
280 opt.map(std::vec::Vec::len),
281 flex,
282 );
283 let body: usize = opt.map_or(0, |v| v.iter().map(|_| 4).sum());
284 prefix + body
285 };
286 }
287 if flex {
288 let known_pairs: Vec<(u32, usize)> = Vec::new();
289 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
290 }
291 n
292 }
293}
294impl Decode<'_> for ReassignablePartition {
295 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
296 let flex = version >= 0;
297 let mut out = Self::default();
298 if version >= 0 {
299 out.partition_index = get_i32(buf)?;
300 }
301 if version >= 0 {
302 out.replicas = {
303 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
304 match opt {
305 None => None,
306 Some(n) => {
307 let mut v = Vec::with_capacity(n);
308 for _ in 0..n {
309 v.push(get_i32(buf)?);
310 }
311 Some(v)
312 }
313 }
314 };
315 }
316 if flex {
317 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
318 }
319 Ok(out)
320 }
321}
322#[cfg(test)]
323impl ReassignablePartition {
324 #[must_use]
325 pub fn populated(version: i16) -> Self {
326 let mut m = Self::default();
327 if version >= 0 {
328 m.partition_index = 1i32;
329 }
330 if version >= 0 {
331 m.replicas = Some(vec![1i32]);
332 }
333 m
334 }
335}
336
337#[must_use]
340#[allow(unused_comparisons)]
341pub fn default_json(version: i16) -> ::serde_json::Value {
342 let mut obj = ::serde_json::Map::new();
343 obj.insert("timeoutMs".to_string(), ::serde_json::json!(60000));
344 if version >= 1 {
345 obj.insert(
346 "allowReplicationFactorChange".to_string(),
347 ::serde_json::Value::Bool(true),
348 );
349 }
350 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
351 ::serde_json::Value::Object(obj)
352}
353
354impl crate::ProtocolRequest for AlterPartitionReassignmentsRequest {
355 const API_KEY: i16 = API_KEY;
356 const MIN_VERSION: i16 = MIN_VERSION;
357 const MAX_VERSION: i16 = MAX_VERSION;
358 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
359 type Response =
360 super::alter_partition_reassignments_response::AlterPartitionReassignmentsResponse;
361}