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