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 bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, put_bool, put_i16, put_i32};
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,
10    string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 19;
16pub const MIN_VERSION: i16 = 2;
17pub const MAX_VERSION: i16 = 7;
18pub const FLEXIBLE_MIN: i16 = 5;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct CreateTopicsRequest {
25    pub topics: Vec<CreatableTopic>,
26    pub timeout_ms: i32,
27    pub validate_only: bool,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl Default for CreateTopicsRequest {
32    fn default() -> Self {
33        Self {
34            topics: Vec::new(),
35            timeout_ms: 60_000i32,
36            validate_only: false,
37            unknown_tagged_fields: Default::default(),
38        }
39    }
40}
41
42impl Encode for CreateTopicsRequest {
43    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
44        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
45            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
46        }
47        let flex = is_flexible(version);
48        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
49        if version >= 0 { put_i32(buf, self.timeout_ms) }
50        if version >= 1 { put_bool(buf, self.validate_only) }
51        if flex {
52            let tagged = WriteTaggedFields::new();
53            tagged.write(buf, &self.unknown_tagged_fields);
54        }
55        Ok(())
56    }
57    fn encoded_len(&self, version: i16) -> usize {
58        let flex = is_flexible(version);
59        let mut n: usize = 0;
60        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
61        if version >= 0 { n += 4; }
62        if version >= 1 { n += 1; }
63        if flex {
64            let known_pairs: Vec<(u32, usize)> = Vec::new();
65            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
66        }
67        n
68    }
69}
70
71impl<'de> Decode<'de> for CreateTopicsRequest {
72    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
73        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
74            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
75        }
76        let flex = is_flexible(version);
77        let mut out = Self::default();
78        if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(CreatableTopic::decode(buf, version)?); } v }; }
79        if version >= 0 { out.timeout_ms = get_i32(buf)?; }
80        if version >= 1 { out.validate_only = get_bool(buf)?; }
81        if flex {
82            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
83                Ok(false)
84            })?;
85        }
86        Ok(out)
87    }
88}
89
90#[derive(Debug, Clone, PartialEq, Eq, Default)]
91pub struct CreatableTopic {
92    pub name: String,
93    pub num_partitions: i32,
94    pub replication_factor: i16,
95    pub assignments: Vec<CreatableReplicaAssignment>,
96    pub configs: Vec<CreatableTopicConfig>,
97    pub unknown_tagged_fields: UnknownTaggedFields,
98}
99
100impl Encode for CreatableTopic {
101    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
102        let flex = version >= 5;
103        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
104        if version >= 0 { put_i32(buf, self.num_partitions) }
105        if version >= 0 { put_i16(buf, self.replication_factor) }
106        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.assignments).len(), flex); for it in &self.assignments { it.encode(buf, version)?; } } }
107        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.configs).len(), flex); for it in &self.configs { it.encode(buf, version)?; } } }
108        if flex {
109            let tagged = WriteTaggedFields::new();
110            tagged.write(buf, &self.unknown_tagged_fields);
111        }
112        Ok(())
113    }
114    fn encoded_len(&self, version: i16) -> usize {
115        let flex = version >= 5;
116        let mut n: usize = 0;
117        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
118        if version >= 0 { n += 4; }
119        if version >= 0 { n += 2; }
120        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.assignments).len(), flex); let body: usize = (self.assignments).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
121        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.configs).len(), flex); let body: usize = (self.configs).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
122        if flex {
123            let known_pairs: Vec<(u32, usize)> = Vec::new();
124            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
125        }
126        n
127    }
128}
129
130impl<'de> Decode<'de> for CreatableTopic {
131    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
132        let flex = version >= 5;
133        let mut out = Self::default();
134        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
135        if version >= 0 { out.num_partitions = get_i32(buf)?; }
136        if version >= 0 { out.replication_factor = get_i16(buf)?; }
137        if version >= 0 { out.assignments = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(CreatableReplicaAssignment::decode(buf, version)?); } v }; }
138        if version >= 0 { out.configs = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(CreatableTopicConfig::decode(buf, version)?); } v }; }
139        if flex {
140            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
141                Ok(false)
142            })?;
143        }
144        Ok(out)
145    }
146}
147
148#[derive(Debug, Clone, PartialEq, Eq, Default)]
149pub struct CreatableReplicaAssignment {
150    pub partition_index: i32,
151    pub broker_ids: Vec<i32>,
152    pub unknown_tagged_fields: UnknownTaggedFields,
153}
154
155impl Encode for CreatableReplicaAssignment {
156    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
157        let flex = version >= 5;
158        if version >= 0 { put_i32(buf, self.partition_index) }
159        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.broker_ids).len(), flex); for it in &self.broker_ids { put_i32(buf, *it); } } }
160        if flex {
161            let tagged = WriteTaggedFields::new();
162            tagged.write(buf, &self.unknown_tagged_fields);
163        }
164        Ok(())
165    }
166    fn encoded_len(&self, version: i16) -> usize {
167        let flex = version >= 5;
168        let mut n: usize = 0;
169        if version >= 0 { n += 4; }
170        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.broker_ids).len(), flex); let body: usize = (self.broker_ids).iter().map(|_| 4).sum(); prefix + body }; }
171        if flex {
172            let known_pairs: Vec<(u32, usize)> = Vec::new();
173            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
174        }
175        n
176    }
177}
178
179impl<'de> Decode<'de> for CreatableReplicaAssignment {
180    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
181        let flex = version >= 5;
182        let mut out = Self::default();
183        if version >= 0 { out.partition_index = get_i32(buf)?; }
184        if version >= 0 { out.broker_ids = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
185        if flex {
186            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
187                Ok(false)
188            })?;
189        }
190        Ok(out)
191    }
192}
193
194#[derive(Debug, Clone, PartialEq, Eq, Default)]
195pub struct CreatableTopicConfig {
196    pub name: String,
197    pub value: Option<String>,
198    pub unknown_tagged_fields: UnknownTaggedFields,
199}
200
201impl Encode for CreatableTopicConfig {
202    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
203        let flex = version >= 5;
204        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
205        if version >= 0 { if flex { put_compact_nullable_string(buf, self.value.as_deref()) } else { put_nullable_string(buf, self.value.as_deref()) } }
206        if flex {
207            let tagged = WriteTaggedFields::new();
208            tagged.write(buf, &self.unknown_tagged_fields);
209        }
210        Ok(())
211    }
212    fn encoded_len(&self, version: i16) -> usize {
213        let flex = version >= 5;
214        let mut n: usize = 0;
215        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
216        if version >= 0 { n += if flex { compact_nullable_string_len(self.value.as_deref()) } else { nullable_string_len(self.value.as_deref()) }; }
217        if flex {
218            let known_pairs: Vec<(u32, usize)> = Vec::new();
219            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
220        }
221        n
222    }
223}
224
225impl<'de> Decode<'de> for CreatableTopicConfig {
226    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
227        let flex = version >= 5;
228        let mut out = Self::default();
229        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
230        if version >= 0 { out.value = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
231        if flex {
232            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
233                Ok(false)
234            })?;
235        }
236        Ok(out)
237    }
238}
239
240/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
241/// Only includes fields valid for the given version.
242#[must_use]
243#[allow(unused_comparisons)]
244pub fn default_json(version: i16) -> ::serde_json::Value {
245    let mut obj = ::serde_json::Map::new();
246    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
247    obj.insert("timeoutMs".to_string(), ::serde_json::json!(60000));
248    if version >= 1 {
249        obj.insert("validateOnly".to_string(), ::serde_json::Value::Bool(false));
250    }
251    ::serde_json::Value::Object(obj)
252}
253
254impl crate::ProtocolRequest for CreateTopicsRequest {
255    const API_KEY: i16 = API_KEY;
256    const MIN_VERSION: i16 = MIN_VERSION;
257    const MAX_VERSION: i16 = MAX_VERSION;
258    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
259    type Response = super::create_topics_response::CreateTopicsResponse;
260}