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