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