Skip to main content

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

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