Skip to main content

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

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