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