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