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