Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
CreateTopicsResponse.owned.rs

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