Skip to main content

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

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