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