kafka_wire_protocol/schema/create_partitions_response/
v1.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, Response};
10use crate::readable_writable::{Readable, Writable};
11#[cfg(test)] use crate::test_utils::proptest_strategies;
12
13/// CreatePartitionsResponse, version 1.
14#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
15#[cfg_attr(test, derive(Arbitrary))]
16pub struct CreatePartitionsResponse {
17    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
18    pub throttle_time_ms: i32,
19    /// The partition creation results for each topic.
20    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
21    pub results: Vec<CreatePartitionsTopicResult>,
22}
23
24impl ApiMessage for CreatePartitionsResponse {
25    fn api_key(&self) -> i16 {
26        37
27    }
28    
29    fn version(&self) -> i16 {
30        1
31    }
32}
33
34impl Response for CreatePartitionsResponse { }
35
36impl Default for CreatePartitionsResponse {
37    fn default() -> Self {
38        CreatePartitionsResponse {
39            throttle_time_ms: 0_i32,
40            results: Vec::<CreatePartitionsTopicResult>::new(),
41        }
42    }
43}
44
45impl CreatePartitionsResponse {
46    pub fn new(throttle_time_ms: i32, results: Vec<CreatePartitionsTopicResult>) -> Self {
47        Self {
48            throttle_time_ms,
49            results,
50        }
51    }
52}
53
54#[cfg(test)]
55mod tests_create_partitions_response_new_and_default {
56    use super::*;
57    
58    #[test]
59    fn test() {
60        let d = CreatePartitionsResponse::new(
61            0_i32,
62            Vec::<CreatePartitionsTopicResult>::new(),
63        );
64        assert_eq!(d, CreatePartitionsResponse::default());
65    }
66}
67
68impl Readable for CreatePartitionsResponse {
69    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
70        let throttle_time_ms = i32::read(input)?;
71        let results = read_array::<CreatePartitionsTopicResult>(input, "results", false)?;
72        Ok(CreatePartitionsResponse {
73            throttle_time_ms, results
74        })
75    }
76}
77
78impl Writable for CreatePartitionsResponse {
79    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
80        self.throttle_time_ms.write(output)?;
81        write_array(output, "self.results", &self.results, false)?;
82        Ok(())
83    }
84}
85
86/// CreatePartitionsTopicResult, version 1.
87#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
88#[cfg_attr(test, derive(Arbitrary))]
89pub struct CreatePartitionsTopicResult {
90    /// The topic name.
91    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
92    pub name: String,
93    /// The result error, or zero if there was no error.
94    pub error_code: i16,
95    /// The result message, or null if there was no error.
96    #[cfg_attr(test, proptest(strategy = "proptest_strategies::optional_string()"))]
97    pub error_message: Option<String>,
98}
99
100impl Default for CreatePartitionsTopicResult {
101    fn default() -> Self {
102        CreatePartitionsTopicResult {
103            name: String::from(""),
104            error_code: 0_i16,
105            error_message: None,
106        }
107    }
108}
109
110impl CreatePartitionsTopicResult {
111    pub fn new<S1: AsRef<str>, S2: AsRef<str>>(name: S1, error_code: i16, error_message: Option<S2>) -> Self {
112        Self {
113            name: name.as_ref().to_string(),
114            error_code,
115            error_message: error_message.map(|s| s.as_ref().to_string()),
116        }
117    }
118}
119
120#[cfg(test)]
121mod tests_create_partitions_topic_result_new_and_default {
122    use super::*;
123    
124    #[test]
125    fn test() {
126        let d = CreatePartitionsTopicResult::new(
127            String::from(""),
128            0_i16,
129            None::<String>,
130        );
131        assert_eq!(d, CreatePartitionsTopicResult::default());
132    }
133}
134
135impl Readable for CreatePartitionsTopicResult {
136    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
137        let name = String::read_ext(input, "name", false)?;
138        let error_code = i16::read(input)?;
139        let error_message = Option::<String>::read_ext(input, "error_message", false)?;
140        Ok(CreatePartitionsTopicResult {
141            name, error_code, error_message
142        })
143    }
144}
145
146impl Writable for CreatePartitionsTopicResult {
147    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
148        self.name.write_ext(output, "self.name", false)?;
149        self.error_code.write(output)?;
150        self.error_message.write_ext(output, "self.error_message", false)?;
151        Ok(())
152    }
153}
154
155#[cfg(test)]
156mod tests {
157    use super::*;
158    use proptest::prelude::*;
159    
160    #[test]
161    fn test_java_default() {
162        crate::test_utils::test_java_default::<CreatePartitionsResponse>("CreatePartitionsResponse", 1);
163    }
164    
165    proptest! {
166        #[test]
167        fn test_serde(data: CreatePartitionsResponse) {
168            crate::test_utils::test_serde(&data)?;
169        }
170    }
171    
172    proptest! {
173        #[test]
174        fn test_java_arbitrary(data: CreatePartitionsResponse) {
175            crate::test_utils::test_java_arbitrary(&data, "CreatePartitionsResponse", 1);
176        }
177    }
178}