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