krabka_protocol/opt/rustwide/workdir/generated/
CreateTopicsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 array::{array_len_prefix_len, get_array_len, put_array_len},
9 fixed::{get_bool, get_i16, get_i32, put_bool, put_i16, put_i32},
10 string_bytes::{
11 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
12 get_compact_string_owned, get_nullable_string_owned, get_string_owned,
13 nullable_string_len, put_compact_nullable_string, put_compact_string,
14 put_nullable_string, put_string, string_len,
15 },
16 },
17 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 19;
20pub const MIN_VERSION: i16 = 2;
21pub const MAX_VERSION: i16 = 7;
22pub const LATEST_STABLE_VERSION: i16 = 7;
23pub const FLEXIBLE_MIN: i16 = 5;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27 version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq)]
30pub struct CreateTopicsRequest {
31 pub topics: Vec<CreatableTopic>,
32 pub timeout_ms: i32,
33 pub validate_only: bool,
34 pub unknown_tagged_fields: UnknownTaggedFields,
35}
36impl Default for CreateTopicsRequest {
37 fn default() -> Self {
38 Self {
39 topics: Vec::new(),
40 timeout_ms: 60_000i32,
41 validate_only: false,
42 unknown_tagged_fields: UnknownTaggedFields::default(),
43 }
44 }
45}
46impl Encode for CreateTopicsRequest {
47 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
48 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
49 return Err(ProtocolError::UnsupportedVersion {
50 api_key: API_KEY,
51 version,
52 });
53 }
54 let flex = is_flexible(version);
55 if version >= 0 {
56 {
57 put_array_len(buf, (self.topics).len(), flex)?;
58 for it in &self.topics {
59 it.encode(buf, version)?;
60 }
61 }
62 }
63 if version >= 0 {
64 put_i32(buf, self.timeout_ms);
65 }
66 if version >= 1 {
67 put_bool(buf, self.validate_only);
68 }
69 if flex {
70 let tagged = WriteTaggedFields::new();
71 tagged.write(buf, &self.unknown_tagged_fields)?;
72 }
73 Ok(())
74 }
75 fn encoded_len(&self, version: i16) -> usize {
76 let flex = is_flexible(version);
77 let mut n: usize = 0;
78 if version >= 0 {
79 n += {
80 let prefix = array_len_prefix_len((self.topics).len(), flex);
81 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
82 prefix + body
83 };
84 }
85 if version >= 0 {
86 n += 4;
87 }
88 if version >= 1 {
89 n += 1;
90 }
91 if flex {
92 let known_pairs: Vec<(u32, usize)> = Vec::new();
93 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
94 }
95 n
96 }
97}
98impl Decode<'_> for CreateTopicsRequest {
99 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
100 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
101 return Err(ProtocolError::UnsupportedVersion {
102 api_key: API_KEY,
103 version,
104 });
105 }
106 let flex = is_flexible(version);
107 let mut out = Self::default();
108 if version >= 0 {
109 out.topics = {
110 let n = get_array_len(buf, flex)?;
111 let mut v = Vec::with_capacity(n);
112 for _ in 0..n {
113 v.push(CreatableTopic::decode(buf, version)?);
114 }
115 v
116 };
117 }
118 if version >= 0 {
119 out.timeout_ms = get_i32(buf)?;
120 }
121 if version >= 1 {
122 out.validate_only = get_bool(buf)?;
123 }
124 if flex {
125 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
126 }
127 Ok(out)
128 }
129}
130#[cfg(test)]
131impl CreateTopicsRequest {
132 #[must_use]
133 pub fn populated(version: i16) -> Self {
134 let mut m = Self::default();
135 if version >= 0 {
136 m.topics = vec![CreatableTopic::populated(version)];
137 }
138 if version >= 0 {
139 m.timeout_ms = 1i32;
140 }
141 if version >= 1 {
142 m.validate_only = true;
143 }
144 m
145 }
146}
147#[derive(Debug, Clone, PartialEq, Eq, Default)]
148pub struct CreatableTopic {
149 pub name: String,
150 pub num_partitions: i32,
151 pub replication_factor: i16,
152 pub assignments: Vec<CreatableReplicaAssignment>,
153 pub configs: Vec<CreatableTopicConfig>,
154 pub unknown_tagged_fields: UnknownTaggedFields,
155}
156impl Encode for CreatableTopic {
157 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
158 let flex = version >= 5;
159 if version >= 0 {
160 if flex {
161 put_compact_string(buf, &self.name)?;
162 } else {
163 put_string(buf, &self.name)?;
164 }
165 }
166 if version >= 0 {
167 put_i32(buf, self.num_partitions);
168 }
169 if version >= 0 {
170 put_i16(buf, self.replication_factor);
171 }
172 if version >= 0 {
173 {
174 put_array_len(buf, (self.assignments).len(), flex)?;
175 for it in &self.assignments {
176 it.encode(buf, version)?;
177 }
178 }
179 }
180 if version >= 0 {
181 {
182 put_array_len(buf, (self.configs).len(), flex)?;
183 for it in &self.configs {
184 it.encode(buf, version)?;
185 }
186 }
187 }
188 if flex {
189 let tagged = WriteTaggedFields::new();
190 tagged.write(buf, &self.unknown_tagged_fields)?;
191 }
192 Ok(())
193 }
194 fn encoded_len(&self, version: i16) -> usize {
195 let flex = version >= 5;
196 let mut n: usize = 0;
197 if version >= 0 {
198 n += if flex {
199 compact_string_len(&self.name)
200 } else {
201 string_len(&self.name)
202 };
203 }
204 if version >= 0 {
205 n += 4;
206 }
207 if version >= 0 {
208 n += 2;
209 }
210 if version >= 0 {
211 n += {
212 let prefix = array_len_prefix_len((self.assignments).len(), flex);
213 let body: usize = (self.assignments)
214 .iter()
215 .map(|it| it.encoded_len(version))
216 .sum();
217 prefix + body
218 };
219 }
220 if version >= 0 {
221 n += {
222 let prefix = array_len_prefix_len((self.configs).len(), flex);
223 let body: usize = (self.configs)
224 .iter()
225 .map(|it| it.encoded_len(version))
226 .sum();
227 prefix + body
228 };
229 }
230 if flex {
231 let known_pairs: Vec<(u32, usize)> = Vec::new();
232 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
233 }
234 n
235 }
236}
237impl Decode<'_> for CreatableTopic {
238 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
239 let flex = version >= 5;
240 let mut out = Self::default();
241 if version >= 0 {
242 out.name = if flex {
243 get_compact_string_owned(buf)?
244 } else {
245 get_string_owned(buf)?
246 };
247 }
248 if version >= 0 {
249 out.num_partitions = get_i32(buf)?;
250 }
251 if version >= 0 {
252 out.replication_factor = get_i16(buf)?;
253 }
254 if version >= 0 {
255 out.assignments = {
256 let n = get_array_len(buf, flex)?;
257 let mut v = Vec::with_capacity(n);
258 for _ in 0..n {
259 v.push(CreatableReplicaAssignment::decode(buf, version)?);
260 }
261 v
262 };
263 }
264 if version >= 0 {
265 out.configs = {
266 let n = get_array_len(buf, flex)?;
267 let mut v = Vec::with_capacity(n);
268 for _ in 0..n {
269 v.push(CreatableTopicConfig::decode(buf, version)?);
270 }
271 v
272 };
273 }
274 if flex {
275 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
276 }
277 Ok(out)
278 }
279}
280#[cfg(test)]
281impl CreatableTopic {
282 #[must_use]
283 pub fn populated(version: i16) -> Self {
284 let mut m = Self::default();
285 if version >= 0 {
286 m.name = "x".to_owned();
287 }
288 if version >= 0 {
289 m.num_partitions = 1i32;
290 }
291 if version >= 0 {
292 m.replication_factor = 1i16;
293 }
294 if version >= 0 {
295 m.assignments = vec![CreatableReplicaAssignment::populated(version)];
296 }
297 if version >= 0 {
298 m.configs = vec![CreatableTopicConfig::populated(version)];
299 }
300 m
301 }
302}
303#[derive(Debug, Clone, PartialEq, Eq, Default)]
304pub struct CreatableReplicaAssignment {
305 pub partition_index: i32,
306 pub broker_ids: Vec<i32>,
307 pub unknown_tagged_fields: UnknownTaggedFields,
308}
309impl Encode for CreatableReplicaAssignment {
310 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
311 let flex = version >= 5;
312 if version >= 0 {
313 put_i32(buf, self.partition_index);
314 }
315 if version >= 0 {
316 {
317 put_array_len(buf, (self.broker_ids).len(), flex)?;
318 for it in &self.broker_ids {
319 put_i32(buf, *it);
320 }
321 }
322 }
323 if flex {
324 let tagged = WriteTaggedFields::new();
325 tagged.write(buf, &self.unknown_tagged_fields)?;
326 }
327 Ok(())
328 }
329 fn encoded_len(&self, version: i16) -> usize {
330 let flex = version >= 5;
331 let mut n: usize = 0;
332 if version >= 0 {
333 n += 4;
334 }
335 if version >= 0 {
336 n += {
337 let prefix = array_len_prefix_len((self.broker_ids).len(), flex);
338 let body: usize = (self.broker_ids).iter().map(|_| 4).sum();
339 prefix + body
340 };
341 }
342 if flex {
343 let known_pairs: Vec<(u32, usize)> = Vec::new();
344 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
345 }
346 n
347 }
348}
349impl Decode<'_> for CreatableReplicaAssignment {
350 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
351 let flex = version >= 5;
352 let mut out = Self::default();
353 if version >= 0 {
354 out.partition_index = get_i32(buf)?;
355 }
356 if version >= 0 {
357 out.broker_ids = {
358 let n = get_array_len(buf, flex)?;
359 let mut v = Vec::with_capacity(n);
360 for _ in 0..n {
361 v.push(get_i32(buf)?);
362 }
363 v
364 };
365 }
366 if flex {
367 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
368 }
369 Ok(out)
370 }
371}
372#[cfg(test)]
373impl CreatableReplicaAssignment {
374 #[must_use]
375 pub fn populated(version: i16) -> Self {
376 let mut m = Self::default();
377 if version >= 0 {
378 m.partition_index = 1i32;
379 }
380 if version >= 0 {
381 m.broker_ids = vec![1i32];
382 }
383 m
384 }
385}
386#[derive(Debug, Clone, PartialEq, Eq)]
387pub struct CreatableTopicConfig {
388 pub name: String,
389 pub value: Option<String>,
390 pub unknown_tagged_fields: UnknownTaggedFields,
391}
392impl Default for CreatableTopicConfig {
393 fn default() -> Self {
394 Self {
395 name: String::new(),
396 value: Some(String::new()),
397 unknown_tagged_fields: UnknownTaggedFields::default(),
398 }
399 }
400}
401impl Encode for CreatableTopicConfig {
402 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
403 let flex = version >= 5;
404 if version >= 0 {
405 if flex {
406 put_compact_string(buf, &self.name)?;
407 } else {
408 put_string(buf, &self.name)?;
409 }
410 }
411 if version >= 0 {
412 if flex {
413 put_compact_nullable_string(buf, self.value.as_deref())?;
414 } else {
415 put_nullable_string(buf, self.value.as_deref())?;
416 }
417 }
418 if flex {
419 let tagged = WriteTaggedFields::new();
420 tagged.write(buf, &self.unknown_tagged_fields)?;
421 }
422 Ok(())
423 }
424 fn encoded_len(&self, version: i16) -> usize {
425 let flex = version >= 5;
426 let mut n: usize = 0;
427 if version >= 0 {
428 n += if flex {
429 compact_string_len(&self.name)
430 } else {
431 string_len(&self.name)
432 };
433 }
434 if version >= 0 {
435 n += if flex {
436 compact_nullable_string_len(self.value.as_deref())
437 } else {
438 nullable_string_len(self.value.as_deref())
439 };
440 }
441 if flex {
442 let known_pairs: Vec<(u32, usize)> = Vec::new();
443 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
444 }
445 n
446 }
447}
448impl Decode<'_> for CreatableTopicConfig {
449 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
450 let flex = version >= 5;
451 let mut out = Self::default();
452 if version >= 0 {
453 out.name = if flex {
454 get_compact_string_owned(buf)?
455 } else {
456 get_string_owned(buf)?
457 };
458 }
459 if version >= 0 {
460 out.value = if flex {
461 get_compact_nullable_string_owned(buf)?
462 } else {
463 get_nullable_string_owned(buf)?
464 };
465 }
466 if flex {
467 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
468 }
469 Ok(out)
470 }
471}
472#[cfg(test)]
473impl CreatableTopicConfig {
474 #[must_use]
475 pub fn populated(version: i16) -> Self {
476 let mut m = Self::default();
477 if version >= 0 {
478 m.name = "x".to_owned();
479 }
480 if version >= 0 {
481 m.value = Some("x".to_owned());
482 }
483 m
484 }
485}
486#[must_use]
489#[allow(unused_comparisons)]
490pub fn default_json(version: i16) -> ::serde_json::Value {
491 let mut obj = ::serde_json::Map::new();
492 obj.insert("topics".to_owned(), ::serde_json::Value::Array(vec![]));
493 obj.insert("timeoutMs".to_owned(), ::serde_json::json!(60_000));
494 if version >= 1 {
495 obj.insert("validateOnly".to_owned(), ::serde_json::Value::Bool(false));
496 }
497 ::serde_json::Value::Object(obj)
498}
499impl crate::ProtocolRequest for CreateTopicsRequest {
500 const API_KEY: i16 = API_KEY;
501 const MIN_VERSION: i16 = MIN_VERSION;
502 const MAX_VERSION: i16 = MAX_VERSION;
503 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
504 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
505 type Response = super::create_topics_response::CreateTopicsResponse;
506}