kafka_wire_protocol/schema/create_topics_request/
v6.rs

1// This file was generated. Do not edit.
2
3use std::io::{Read, Result, Write};
4
5use serde::{Deserialize, Serialize};
6#[cfg(test)] use proptest_derive::Arbitrary;
7
8use crate::arrays::{read_array, write_array};
9use crate::markers::{ApiMessage, Request};
10use crate::readable_writable::{Readable, Writable};
11use crate::tagged_fields::{RawTaggedField, read_tagged_fields, write_tagged_fields};
12#[cfg(test)] use crate::test_utils::proptest_strategies;
13
14/// CreateTopicsRequest, version 6.
15#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
16#[cfg_attr(test, derive(Arbitrary))]
17pub struct CreateTopicsRequest {
18    /// The topics to create.
19    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
20    pub topics: Vec<CreatableTopic>,
21    /// How long to wait in milliseconds before timing out the request.
22    pub timeout_ms: i32,
23    /// If true, check that the topics can be created as specified, but don't create anything.
24    pub validate_only: bool,
25    /// Unknown tagged fields.
26    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
27    pub _unknown_tagged_fields: Vec<RawTaggedField>,
28}
29
30impl ApiMessage for CreateTopicsRequest {
31    fn api_key(&self) -> i16 {
32        19
33    }
34    
35    fn version(&self) -> i16 {
36        6
37    }
38}
39
40impl Request for CreateTopicsRequest { }
41
42impl Default for CreateTopicsRequest {
43    fn default() -> Self {
44        CreateTopicsRequest {
45            topics: Vec::<CreatableTopic>::new(),
46            timeout_ms: 60000_i32,
47            validate_only: false,
48            _unknown_tagged_fields: Vec::new(),
49        }
50    }
51}
52
53impl CreateTopicsRequest {
54    pub fn new(topics: Vec<CreatableTopic>, timeout_ms: i32, validate_only: bool) -> Self {
55        Self {
56            topics,
57            timeout_ms,
58            validate_only,
59            _unknown_tagged_fields: vec![],
60        }
61    }
62}
63
64#[cfg(test)]
65mod tests_create_topics_request_new_and_default {
66    use super::*;
67    
68    #[test]
69    fn test() {
70        let d = CreateTopicsRequest::new(
71            Vec::<CreatableTopic>::new(),
72            60000_i32,
73            false,
74        );
75        assert_eq!(d, CreateTopicsRequest::default());
76    }
77}
78
79impl Readable for CreateTopicsRequest {
80    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
81        let topics = read_array::<CreatableTopic>(input, "topics", true)?;
82        let timeout_ms = i32::read(input)?;
83        let validate_only = bool::read(input)?;
84        let tagged_fields_callback = |tag: i32, _: &[u8]| {
85            match tag {
86                _ => Ok(false)
87            }
88        };
89        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
90        Ok(CreateTopicsRequest {
91            topics, timeout_ms, validate_only, _unknown_tagged_fields
92        })
93    }
94}
95
96impl Writable for CreateTopicsRequest {
97    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
98        write_array(output, "self.topics", &self.topics, true)?;
99        self.timeout_ms.write(output)?;
100        self.validate_only.write(output)?;
101        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
102        Ok(())
103    }
104}
105
106/// CreatableTopic, version 6.
107#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
108#[cfg_attr(test, derive(Arbitrary))]
109pub struct CreatableTopic {
110    /// The topic name.
111    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
112    pub name: String,
113    /// The number of partitions to create in the topic, or -1 if we are either specifying a manual partition assignment or using the default partitions.
114    pub num_partitions: i32,
115    /// The number of replicas to create for each partition in the topic, or -1 if we are either specifying a manual partition assignment or using the default replication factor.
116    pub replication_factor: i16,
117    /// The manual partition assignment, or the empty array if we are using automatic assignment.
118    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
119    pub assignments: Vec<CreatableReplicaAssignment>,
120    /// The custom topic configurations to set.
121    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
122    pub configs: Vec<CreatableTopicConfig>,
123    /// Unknown tagged fields.
124    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
125    pub _unknown_tagged_fields: Vec<RawTaggedField>,
126}
127
128impl Default for CreatableTopic {
129    fn default() -> Self {
130        CreatableTopic {
131            name: String::from(""),
132            num_partitions: 0_i32,
133            replication_factor: 0_i16,
134            assignments: Vec::<CreatableReplicaAssignment>::new(),
135            configs: Vec::<CreatableTopicConfig>::new(),
136            _unknown_tagged_fields: Vec::new(),
137        }
138    }
139}
140
141impl CreatableTopic {
142    pub fn new<S1: AsRef<str>>(name: S1, num_partitions: i32, replication_factor: i16, assignments: Vec<CreatableReplicaAssignment>, configs: Vec<CreatableTopicConfig>) -> Self {
143        Self {
144            name: name.as_ref().to_string(),
145            num_partitions,
146            replication_factor,
147            assignments,
148            configs,
149            _unknown_tagged_fields: vec![],
150        }
151    }
152}
153
154#[cfg(test)]
155mod tests_creatable_topic_new_and_default {
156    use super::*;
157    
158    #[test]
159    fn test() {
160        let d = CreatableTopic::new(
161            String::from(""),
162            0_i32,
163            0_i16,
164            Vec::<CreatableReplicaAssignment>::new(),
165            Vec::<CreatableTopicConfig>::new(),
166        );
167        assert_eq!(d, CreatableTopic::default());
168    }
169}
170
171impl Readable for CreatableTopic {
172    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
173        let name = String::read_ext(input, "name", true)?;
174        let num_partitions = i32::read(input)?;
175        let replication_factor = i16::read(input)?;
176        let assignments = read_array::<CreatableReplicaAssignment>(input, "assignments", true)?;
177        let configs = read_array::<CreatableTopicConfig>(input, "configs", true)?;
178        let tagged_fields_callback = |tag: i32, _: &[u8]| {
179            match tag {
180                _ => Ok(false)
181            }
182        };
183        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
184        Ok(CreatableTopic {
185            name, num_partitions, replication_factor, assignments, configs, _unknown_tagged_fields
186        })
187    }
188}
189
190impl Writable for CreatableTopic {
191    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
192        self.name.write_ext(output, "self.name", true)?;
193        self.num_partitions.write(output)?;
194        self.replication_factor.write(output)?;
195        write_array(output, "self.assignments", &self.assignments, true)?;
196        write_array(output, "self.configs", &self.configs, true)?;
197        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
198        Ok(())
199    }
200}
201
202/// CreatableReplicaAssignment, version 6.
203#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
204#[cfg_attr(test, derive(Arbitrary))]
205pub struct CreatableReplicaAssignment {
206    /// The partition index.
207    pub partition_index: i32,
208    /// The brokers to place the partition on.
209    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
210    pub broker_ids: Vec<i32>,
211    /// Unknown tagged fields.
212    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
213    pub _unknown_tagged_fields: Vec<RawTaggedField>,
214}
215
216impl Default for CreatableReplicaAssignment {
217    fn default() -> Self {
218        CreatableReplicaAssignment {
219            partition_index: 0_i32,
220            broker_ids: Vec::<i32>::new(),
221            _unknown_tagged_fields: Vec::new(),
222        }
223    }
224}
225
226impl CreatableReplicaAssignment {
227    pub fn new(partition_index: i32, broker_ids: Vec<i32>) -> Self {
228        Self {
229            partition_index,
230            broker_ids,
231            _unknown_tagged_fields: vec![],
232        }
233    }
234}
235
236#[cfg(test)]
237mod tests_creatable_replica_assignment_new_and_default {
238    use super::*;
239    
240    #[test]
241    fn test() {
242        let d = CreatableReplicaAssignment::new(
243            0_i32,
244            Vec::<i32>::new(),
245        );
246        assert_eq!(d, CreatableReplicaAssignment::default());
247    }
248}
249
250impl Readable for CreatableReplicaAssignment {
251    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
252        let partition_index = i32::read(input)?;
253        let broker_ids = read_array::<i32>(input, "broker_ids", true)?;
254        let tagged_fields_callback = |tag: i32, _: &[u8]| {
255            match tag {
256                _ => Ok(false)
257            }
258        };
259        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
260        Ok(CreatableReplicaAssignment {
261            partition_index, broker_ids, _unknown_tagged_fields
262        })
263    }
264}
265
266impl Writable for CreatableReplicaAssignment {
267    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
268        self.partition_index.write(output)?;
269        write_array(output, "self.broker_ids", &self.broker_ids, true)?;
270        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
271        Ok(())
272    }
273}
274
275/// CreatableTopicConfig, version 6.
276#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
277#[cfg_attr(test, derive(Arbitrary))]
278pub struct CreatableTopicConfig {
279    /// The configuration name.
280    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
281    pub name: String,
282    /// The configuration value.
283    #[cfg_attr(test, proptest(strategy = "proptest_strategies::optional_string()"))]
284    pub value: Option<String>,
285    /// Unknown tagged fields.
286    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
287    pub _unknown_tagged_fields: Vec<RawTaggedField>,
288}
289
290impl Default for CreatableTopicConfig {
291    fn default() -> Self {
292        CreatableTopicConfig {
293            name: String::from(""),
294            value: Some(String::from("")),
295            _unknown_tagged_fields: Vec::new(),
296        }
297    }
298}
299
300impl CreatableTopicConfig {
301    pub fn new<S1: AsRef<str>, S2: AsRef<str>>(name: S1, value: Option<S2>) -> Self {
302        Self {
303            name: name.as_ref().to_string(),
304            value: value.map(|s| s.as_ref().to_string()),
305            _unknown_tagged_fields: vec![],
306        }
307    }
308}
309
310#[cfg(test)]
311mod tests_creatable_topic_config_new_and_default {
312    use super::*;
313    
314    #[test]
315    fn test() {
316        let d = CreatableTopicConfig::new(
317            String::from(""),
318            Some(String::from("")),
319        );
320        assert_eq!(d, CreatableTopicConfig::default());
321    }
322}
323
324impl Readable for CreatableTopicConfig {
325    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
326        let name = String::read_ext(input, "name", true)?;
327        let value = Option::<String>::read_ext(input, "value", true)?;
328        let tagged_fields_callback = |tag: i32, _: &[u8]| {
329            match tag {
330                _ => Ok(false)
331            }
332        };
333        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
334        Ok(CreatableTopicConfig {
335            name, value, _unknown_tagged_fields
336        })
337    }
338}
339
340impl Writable for CreatableTopicConfig {
341    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
342        self.name.write_ext(output, "self.name", true)?;
343        self.value.write_ext(output, "self.value", true)?;
344        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
345        Ok(())
346    }
347}
348
349#[cfg(test)]
350mod tests {
351    use super::*;
352    use proptest::prelude::*;
353    
354    #[test]
355    fn test_java_default() {
356        crate::test_utils::test_java_default::<CreateTopicsRequest>("CreateTopicsRequest", 6);
357    }
358    
359    proptest! {
360        #[test]
361        fn test_serde(data: CreateTopicsRequest) {
362            crate::test_utils::test_serde(&data)?;
363        }
364    }
365    
366    proptest! {
367        #[test]
368        fn test_java_arbitrary(data: CreateTopicsRequest) {
369            crate::test_utils::test_java_arbitrary(&data, "CreateTopicsRequest", 6);
370        }
371    }
372}