kafka_wire_protocol/schema/create_topics_response/
v2.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/// CreateTopicsResponse, version 2.
14#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
15#[cfg_attr(test, derive(Arbitrary))]
16pub struct CreateTopicsResponse {
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    /// Results for each topic we tried to create.
20    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
21    pub topics: Vec<CreatableTopicResult>,
22}
23
24impl ApiMessage for CreateTopicsResponse {
25    fn api_key(&self) -> i16 {
26        19
27    }
28    
29    fn version(&self) -> i16 {
30        2
31    }
32}
33
34impl Response for CreateTopicsResponse { }
35
36impl Default for CreateTopicsResponse {
37    fn default() -> Self {
38        CreateTopicsResponse {
39            throttle_time_ms: 0_i32,
40            topics: Vec::<CreatableTopicResult>::new(),
41        }
42    }
43}
44
45impl CreateTopicsResponse {
46    pub fn new(throttle_time_ms: i32, topics: Vec<CreatableTopicResult>) -> Self {
47        Self {
48            throttle_time_ms,
49            topics,
50        }
51    }
52}
53
54#[cfg(test)]
55mod tests_create_topics_response_new_and_default {
56    use super::*;
57    
58    #[test]
59    fn test() {
60        let d = CreateTopicsResponse::new(
61            0_i32,
62            Vec::<CreatableTopicResult>::new(),
63        );
64        assert_eq!(d, CreateTopicsResponse::default());
65    }
66}
67
68impl Readable for CreateTopicsResponse {
69    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
70        let throttle_time_ms = i32::read(input)?;
71        let topics = read_array::<CreatableTopicResult>(input, "topics", false)?;
72        Ok(CreateTopicsResponse {
73            throttle_time_ms, topics
74        })
75    }
76}
77
78impl Writable for CreateTopicsResponse {
79    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
80        self.throttle_time_ms.write(output)?;
81        write_array(output, "self.topics", &self.topics, false)?;
82        Ok(())
83    }
84}
85
86/// CreatableTopicResult, version 2.
87#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
88#[cfg_attr(test, derive(Arbitrary))]
89pub struct CreatableTopicResult {
90    /// The topic name.
91    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
92    pub name: String,
93    /// The error code, or 0 if there was no error.
94    pub error_code: i16,
95    /// The error 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 CreatableTopicResult {
101    fn default() -> Self {
102        CreatableTopicResult {
103            name: String::from(""),
104            error_code: 0_i16,
105            error_message: Some(String::from("")),
106        }
107    }
108}
109
110impl CreatableTopicResult {
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_creatable_topic_result_new_and_default {
122    use super::*;
123    
124    #[test]
125    fn test() {
126        let d = CreatableTopicResult::new(
127            String::from(""),
128            0_i16,
129            Some(String::from("")),
130        );
131        assert_eq!(d, CreatableTopicResult::default());
132    }
133}
134
135impl Readable for CreatableTopicResult {
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(CreatableTopicResult {
141            name, error_code, error_message
142        })
143    }
144}
145
146impl Writable for CreatableTopicResult {
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::<CreateTopicsResponse>("CreateTopicsResponse", 2);
163    }
164    
165    proptest! {
166        #[test]
167        fn test_serde(data: CreateTopicsResponse) {
168            crate::test_utils::test_serde(&data)?;
169        }
170    }
171    
172    proptest! {
173        #[test]
174        fn test_java_arbitrary(data: CreateTopicsResponse) {
175            crate::test_utils::test_java_arbitrary(&data, "CreateTopicsResponse", 2);
176        }
177    }
178}