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