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