kacrab_protocol/generated/
create_topics_response.rs1#![allow(
3 missing_docs,
4 clippy::all,
5 clippy::pedantic,
6 clippy::nursery,
7 clippy::arithmetic_side_effects,
8 reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9 hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct CreateTopicsResponseData {
17 pub throttle_time_ms: i32,
20 pub topics: Vec<CreatableTopicResult>,
22 pub _unknown_tagged_fields: Vec<RawTaggedField>,
23}
24impl Default for CreateTopicsResponseData {
25 fn default() -> Self {
26 Self {
27 throttle_time_ms: 0_i32,
28 topics: Vec::new(),
29 _unknown_tagged_fields: Vec::new(),
30 }
31 }
32}
33impl CreateTopicsResponseData {
34 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
35 self.throttle_time_ms = value;
36 self
37 }
38 pub fn with_topics(mut self, value: Vec<CreatableTopicResult>) -> Self {
39 self.topics = value;
40 self
41 }
42 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
43 if version < 2 || version > 7 {
44 return Err(UnsupportedVersion::new(19, version).into());
45 }
46 let throttle_time_ms;
47 let topics;
48 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
49 throttle_time_ms = read_i32(buf)?;
50 if version >= 5 {
51 topics = {
52 let len = read_compact_array_length(buf)?;
53 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
54 for _ in 0..len {
55 arr.push(CreatableTopicResult::read(buf, version)?);
56 }
57 arr
58 };
59 } else {
60 topics = {
61 let len = read_array_length(buf)?;
62 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
63 for _ in 0..len {
64 arr.push(CreatableTopicResult::read(buf, version)?);
65 }
66 arr
67 };
68 }
69 if version >= 5 {
70 let tagged_fields = read_tagged_fields(buf)?;
71 for field in &tagged_fields {
72 match field.tag {
73 _ => {
74 _unknown_tagged_fields.push(field.clone());
75 },
76 }
77 }
78 }
79 Ok(Self {
80 throttle_time_ms,
81 topics,
82 _unknown_tagged_fields,
83 })
84 }
85 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
86 if version < 2 || version > 7 {
87 return Err(UnsupportedVersion::new(19, version).into());
88 }
89 write_i32(buf, self.throttle_time_ms);
90 if version >= 5 {
91 write_compact_array_length(buf, self.topics.len() as i32);
92 for el in &self.topics {
93 el.write(buf, version)?;
94 }
95 } else {
96 write_array_length(buf, self.topics.len() as i32);
97 for el in &self.topics {
98 el.write(buf, version)?;
99 }
100 }
101 if version >= 5 {
102 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
103 all_tags.sort_by_key(|f| f.tag);
104 write_tagged_fields(buf, &all_tags)?;
105 }
106 Ok(())
107 }
108 pub fn encoded_len(&self, version: i16) -> Result<usize> {
109 if version < 2 || version > 7 {
110 return Err(UnsupportedVersion::new(19, version).into());
111 }
112 let mut len: usize = 0;
113 len += 4;
114 if version >= 5 {
115 len += compact_array_length_len(self.topics.len() as i32);
116 for el in &self.topics {
117 len += el.encoded_len(version)?;
118 }
119 } else {
120 len += array_length_len();
121 for el in &self.topics {
122 len += el.encoded_len(version)?;
123 }
124 }
125 if version >= 5 {
126 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
127 all_tags.sort_by_key(|f| f.tag);
128 len += tagged_fields_len(&all_tags)?;
129 }
130 Ok(len)
131 }
132}
133#[derive(Debug, Clone, PartialEq)]
134pub struct CreatableTopicResult {
135 pub name: KafkaString,
137 pub topic_id: KafkaUuid,
139 pub error_code: i16,
141 pub error_message: Option<KafkaString>,
143 pub topic_config_error_code: i16,
145 pub num_partitions: i32,
147 pub replication_factor: i16,
149 pub configs: Option<Vec<CreatableTopicConfigs>>,
151 pub _unknown_tagged_fields: Vec<RawTaggedField>,
152}
153impl Default for CreatableTopicResult {
154 fn default() -> Self {
155 Self {
156 name: KafkaString::default(),
157 topic_id: KafkaUuid::ZERO,
158 error_code: 0_i16,
159 error_message: None,
160 topic_config_error_code: 0_i16,
161 num_partitions: -1i32,
162 replication_factor: -1i16,
163 configs: None,
164 _unknown_tagged_fields: Vec::new(),
165 }
166 }
167}
168impl CreatableTopicResult {
169 pub fn with_name(mut self, value: KafkaString) -> Self {
170 self.name = value;
171 self
172 }
173 pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
174 self.topic_id = value;
175 self
176 }
177 pub fn with_error_code(mut self, value: i16) -> Self {
178 self.error_code = value;
179 self
180 }
181 pub fn with_error_message(mut self, value: Option<KafkaString>) -> Self {
182 self.error_message = value;
183 self
184 }
185 pub fn with_topic_config_error_code(mut self, value: i16) -> Self {
186 self.topic_config_error_code = value;
187 self
188 }
189 pub fn with_num_partitions(mut self, value: i32) -> Self {
190 self.num_partitions = value;
191 self
192 }
193 pub fn with_replication_factor(mut self, value: i16) -> Self {
194 self.replication_factor = value;
195 self
196 }
197 pub fn with_configs(mut self, value: Option<Vec<CreatableTopicConfigs>>) -> Self {
198 self.configs = value;
199 self
200 }
201 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
202 let name;
203 let mut topic_id = KafkaUuid::ZERO;
204 let error_code;
205 let error_message;
206 let mut topic_config_error_code = 0_i16;
207 let mut num_partitions = -1i32;
208 let mut replication_factor = -1i16;
209 let mut configs = None;
210 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
211 if version >= 5 {
212 name = read_compact_string(buf)?;
213 } else {
214 name = read_string(buf)?;
215 }
216 if version >= 7 {
217 topic_id = read_uuid(buf)?;
218 }
219 error_code = read_i16(buf)?;
220 if version >= 5 {
221 error_message = read_compact_nullable_string(buf)?;
222 } else {
223 error_message = read_nullable_string(buf)?;
224 }
225 if version >= 5 {
226 num_partitions = read_i32(buf)?;
227 }
228 if version >= 5 {
229 replication_factor = read_i16(buf)?;
230 }
231 if version >= 5 {
232 configs = {
233 let len = read_compact_array_length(buf)?;
234 if len < 0 {
235 None
236 } else {
237 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
238 for _ in 0..len {
239 arr.push(CreatableTopicConfigs::read(buf, version)?);
240 }
241 Some(arr)
242 }
243 };
244 }
245 if version >= 5 {
246 let tagged_fields = read_tagged_fields(buf)?;
247 for field in &tagged_fields {
248 match field.tag {
249 0 => {
250 let mut tag_buf = field.data.clone();
251 topic_config_error_code = read_i16(&mut tag_buf)?;
252 },
253 _ => {
254 _unknown_tagged_fields.push(field.clone());
255 },
256 }
257 }
258 }
259 Ok(Self {
260 name,
261 topic_id,
262 error_code,
263 error_message,
264 topic_config_error_code,
265 num_partitions,
266 replication_factor,
267 configs,
268 _unknown_tagged_fields,
269 })
270 }
271 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
272 if version >= 5 {
273 write_compact_string(buf, &self.name)?;
274 } else {
275 write_string(buf, &self.name)?;
276 }
277 if version >= 7 {
278 write_uuid(buf, &self.topic_id);
279 } else if self.topic_id != KafkaUuid::ZERO {
280 return Err(UnsupportedFieldVersion::new(19, "topic_id", version).into());
281 }
282 write_i16(buf, self.error_code);
283 if version >= 5 {
284 write_compact_nullable_string(buf, self.error_message.as_ref())?;
285 } else {
286 write_nullable_string(buf, self.error_message.as_ref())?;
287 }
288 if version >= 5 {
289 write_i32(buf, self.num_partitions);
290 } else if self.num_partitions != -1i32 {
291 return Err(UnsupportedFieldVersion::new(19, "num_partitions", version).into());
292 }
293 if version >= 5 {
294 write_i16(buf, self.replication_factor);
295 } else if self.replication_factor != -1i16 {
296 return Err(UnsupportedFieldVersion::new(19, "replication_factor", version).into());
297 }
298 if version >= 5 {
299 match &self.configs {
300 None => {
301 write_compact_array_length(buf, -1);
302 },
303 Some(arr) => {
304 write_compact_array_length(buf, arr.len() as i32);
305 for el in arr {
306 el.write(buf, version)?;
307 }
308 },
309 }
310 } else if self.configs != None {
311 return Err(UnsupportedFieldVersion::new(19, "configs", version).into());
312 }
313 if version >= 5 {
314 let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
315 if self.topic_config_error_code != 0_i16 {
316 let mut tag_buf = BytesMut::new();
317 write_i16(&mut tag_buf, self.topic_config_error_code);
318 known_tagged_fields.push(RawTaggedField {
319 tag: 0,
320 data: tag_buf.freeze(),
321 });
322 }
323 let mut all_tags = known_tagged_fields;
324 all_tags.extend(self._unknown_tagged_fields.iter().cloned());
325 all_tags.sort_by_key(|f| f.tag);
326 write_tagged_fields(buf, &all_tags)?;
327 }
328 Ok(())
329 }
330 pub fn encoded_len(&self, version: i16) -> Result<usize> {
331 let mut len: usize = 0;
332 if version >= 5 {
333 len += compact_string_len(&self.name)?;
334 } else {
335 len += string_len(&self.name)?;
336 }
337 if version >= 7 {
338 len += 16;
339 } else if self.topic_id != KafkaUuid::ZERO {
340 return Err(UnsupportedFieldVersion::new(19, "topic_id", version).into());
341 }
342 len += 2;
343 if version >= 5 {
344 len += compact_nullable_string_len(self.error_message.as_ref())?;
345 } else {
346 len += nullable_string_len(self.error_message.as_ref())?;
347 }
348 if version >= 5 {
349 len += 4;
350 } else if self.num_partitions != -1i32 {
351 return Err(UnsupportedFieldVersion::new(19, "num_partitions", version).into());
352 }
353 if version >= 5 {
354 len += 2;
355 } else if self.replication_factor != -1i16 {
356 return Err(UnsupportedFieldVersion::new(19, "replication_factor", version).into());
357 }
358 if version >= 5 {
359 match &self.configs {
360 None => {
361 len += compact_array_length_len(-1);
362 },
363 Some(arr) => {
364 len += compact_array_length_len(arr.len() as i32);
365 for el in arr {
366 len += el.encoded_len(version)?;
367 }
368 },
369 }
370 } else if self.configs != None {
371 return Err(UnsupportedFieldVersion::new(19, "configs", version).into());
372 }
373 if version >= 5 {
374 let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
375 if self.topic_config_error_code != 0_i16 {
376 let mut tag_buf = BytesMut::new();
377 write_i16(&mut tag_buf, self.topic_config_error_code);
378 known_tagged_fields.push(RawTaggedField {
379 tag: 0,
380 data: tag_buf.freeze(),
381 });
382 }
383 let mut all_tags = known_tagged_fields;
384 all_tags.extend(self._unknown_tagged_fields.iter().cloned());
385 all_tags.sort_by_key(|f| f.tag);
386 len += tagged_fields_len(&all_tags)?;
387 }
388 Ok(len)
389 }
390}
391#[derive(Debug, Clone, PartialEq)]
392pub struct CreatableTopicConfigs {
393 pub name: KafkaString,
395 pub value: Option<KafkaString>,
397 pub read_only: bool,
399 pub config_source: i8,
401 pub is_sensitive: bool,
403 pub _unknown_tagged_fields: Vec<RawTaggedField>,
404}
405impl Default for CreatableTopicConfigs {
406 fn default() -> Self {
407 Self {
408 name: KafkaString::default(),
409 value: None,
410 read_only: false,
411 config_source: -1i8,
412 is_sensitive: false,
413 _unknown_tagged_fields: Vec::new(),
414 }
415 }
416}
417impl CreatableTopicConfigs {
418 pub fn with_name(mut self, value: KafkaString) -> Self {
419 self.name = value;
420 self
421 }
422 pub fn with_value(mut self, value: Option<KafkaString>) -> Self {
423 self.value = value;
424 self
425 }
426 pub fn with_read_only(mut self, value: bool) -> Self {
427 self.read_only = value;
428 self
429 }
430 pub fn with_config_source(mut self, value: i8) -> Self {
431 self.config_source = value;
432 self
433 }
434 pub fn with_is_sensitive(mut self, value: bool) -> Self {
435 self.is_sensitive = value;
436 self
437 }
438 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
439 let name;
440 let value;
441 let read_only;
442 let config_source;
443 let is_sensitive;
444 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
445 name = read_compact_string(buf)?;
446 value = read_compact_nullable_string(buf)?;
447 read_only = read_bool(buf)?;
448 config_source = read_i8(buf)?;
449 is_sensitive = read_bool(buf)?;
450 let tagged_fields = read_tagged_fields(buf)?;
451 for field in &tagged_fields {
452 match field.tag {
453 _ => {
454 _unknown_tagged_fields.push(field.clone());
455 },
456 }
457 }
458 Ok(Self {
459 name,
460 value,
461 read_only,
462 config_source,
463 is_sensitive,
464 _unknown_tagged_fields,
465 })
466 }
467 pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
468 write_compact_string(buf, &self.name)?;
469 write_compact_nullable_string(buf, self.value.as_ref())?;
470 write_bool(buf, self.read_only);
471 write_i8(buf, self.config_source);
472 write_bool(buf, self.is_sensitive);
473 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
474 all_tags.sort_by_key(|f| f.tag);
475 write_tagged_fields(buf, &all_tags)?;
476 Ok(())
477 }
478 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
479 let mut len: usize = 0;
480 len += compact_string_len(&self.name)?;
481 len += compact_nullable_string_len(self.value.as_ref())?;
482 len += 1;
483 len += 1;
484 len += 1;
485 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
486 all_tags.sort_by_key(|f| f.tag);
487 len += tagged_fields_len(&all_tags)?;
488 Ok(len)
489 }
490}