1use std::io::{Cursor, Read, Result, Write};
4
5use serde::{Deserialize, Serialize};
6#[cfg(test)] use proptest_derive::Arbitrary;
7
8use crate::arrays::{read_array, read_nullable_array, write_array, write_nullable_array};
9use crate::markers::{ApiMessage, Response};
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#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
16#[cfg_attr(test, derive(Arbitrary))]
17pub struct CreateTopicsResponse {
18 pub throttle_time_ms: i32,
20 #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
22 pub topics: Vec<CreatableTopicResult>,
23 #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
25 pub _unknown_tagged_fields: Vec<RawTaggedField>,
26}
27
28impl ApiMessage for CreateTopicsResponse {
29 fn api_key(&self) -> i16 {
30 19
31 }
32
33 fn version(&self) -> i16 {
34 6
35 }
36}
37
38impl Response for CreateTopicsResponse { }
39
40impl Default for CreateTopicsResponse {
41 fn default() -> Self {
42 CreateTopicsResponse {
43 throttle_time_ms: 0_i32,
44 topics: Vec::<CreatableTopicResult>::new(),
45 _unknown_tagged_fields: Vec::new(),
46 }
47 }
48}
49
50impl CreateTopicsResponse {
51 pub fn new(throttle_time_ms: i32, topics: Vec<CreatableTopicResult>) -> Self {
52 Self {
53 throttle_time_ms,
54 topics,
55 _unknown_tagged_fields: vec![],
56 }
57 }
58}
59
60#[cfg(test)]
61mod tests_create_topics_response_new_and_default {
62 use super::*;
63
64 #[test]
65 fn test() {
66 let d = CreateTopicsResponse::new(
67 0_i32,
68 Vec::<CreatableTopicResult>::new(),
69 );
70 assert_eq!(d, CreateTopicsResponse::default());
71 }
72}
73
74impl Readable for CreateTopicsResponse {
75 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
76 let throttle_time_ms = i32::read(input)?;
77 let topics = read_array::<CreatableTopicResult>(input, "topics", true)?;
78 let tagged_fields_callback = |tag: i32, _: &[u8]| {
79 match tag {
80 _ => Ok(false)
81 }
82 };
83 let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
84 Ok(CreateTopicsResponse {
85 throttle_time_ms, topics, _unknown_tagged_fields
86 })
87 }
88}
89
90impl Writable for CreateTopicsResponse {
91 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
92 self.throttle_time_ms.write(output)?;
93 write_array(output, "self.topics", &self.topics, true)?;
94 write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
95 Ok(())
96 }
97}
98
99#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
101#[cfg_attr(test, derive(Arbitrary))]
102pub struct CreatableTopicResult {
103 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
105 pub name: String,
106 pub error_code: i16,
108 #[cfg_attr(test, proptest(strategy = "proptest_strategies::optional_string()"))]
110 pub error_message: Option<String>,
111 pub topic_config_error_code: i16,
113 pub num_partitions: i32,
115 pub replication_factor: i16,
117 #[cfg_attr(test, proptest(strategy = "proptest_strategies::optional_vec()"))]
119 pub configs: Option<Vec<CreatableTopicConfigs>>,
120 #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
122 pub _unknown_tagged_fields: Vec<RawTaggedField>,
123}
124
125impl Default for CreatableTopicResult {
126 fn default() -> Self {
127 CreatableTopicResult {
128 name: String::from(""),
129 error_code: 0_i16,
130 error_message: Some(String::from("")),
131 topic_config_error_code: 0_i16,
132 num_partitions: -1_i32,
133 replication_factor: -1_i16,
134 configs: Some(Vec::<CreatableTopicConfigs>::new()),
135 _unknown_tagged_fields: Vec::new(),
136 }
137 }
138}
139
140impl CreatableTopicResult {
141 pub fn new<S1: AsRef<str>, S2: AsRef<str>>(name: S1, error_code: i16, error_message: Option<S2>, topic_config_error_code: i16, num_partitions: i32, replication_factor: i16, configs: Option<Vec<CreatableTopicConfigs>>) -> Self {
142 Self {
143 name: name.as_ref().to_string(),
144 error_code,
145 error_message: error_message.map(|s| s.as_ref().to_string()),
146 topic_config_error_code,
147 num_partitions,
148 replication_factor,
149 configs,
150 _unknown_tagged_fields: vec![],
151 }
152 }
153}
154
155#[cfg(test)]
156mod tests_creatable_topic_result_new_and_default {
157 use super::*;
158
159 #[test]
160 fn test() {
161 let d = CreatableTopicResult::new(
162 String::from(""),
163 0_i16,
164 Some(String::from("")),
165 0_i16,
166 -1_i32,
167 -1_i16,
168 Some(Vec::<CreatableTopicConfigs>::new()),
169 );
170 assert_eq!(d, CreatableTopicResult::default());
171 }
172}
173
174impl Readable for CreatableTopicResult {
175 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
176 let name = String::read_ext(input, "name", true)?;
177 let error_code = i16::read(input)?;
178 let error_message = Option::<String>::read_ext(input, "error_message", true)?;
179 let mut topic_config_error_code = 0_i16;
180 let num_partitions = i32::read(input)?;
181 let replication_factor = i16::read(input)?;
182 let configs = read_nullable_array::<CreatableTopicConfigs>(input, "configs", true)?;
183 let tagged_fields_callback = |tag: i32, tag_data: &[u8]| {
184 match tag {
185 0 => {
186 let mut cur = Cursor::new(tag_data);
187 topic_config_error_code = i16::read(&mut cur)?;
188 Ok(true)
189 },
190 _ => Ok(false)
191 }
192 };
193 let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
194 Ok(CreatableTopicResult {
195 name, error_code, error_message, topic_config_error_code, num_partitions, replication_factor, configs, _unknown_tagged_fields
196 })
197 }
198}
199
200impl Writable for CreatableTopicResult {
201 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
202 self.name.write_ext(output, "self.name", true)?;
203 self.error_code.write(output)?;
204 self.error_message.write_ext(output, "self.error_message", true)?;
205 self.num_partitions.write(output)?;
206 self.replication_factor.write(output)?;
207 write_nullable_array(output, "self.configs", self.configs.as_deref(), true)?;
208 let mut known_tagged_fields = Vec::<RawTaggedField>::new();
209 if self.topic_config_error_code != 0_i16 {
210 let mut cur = Cursor::new(Vec::<u8>::new());
211 self.topic_config_error_code.write(&mut cur)?;
212 known_tagged_fields.push(RawTaggedField { tag: 0, data: cur.into_inner() });
213 }
214 write_tagged_fields(output, &known_tagged_fields, &self._unknown_tagged_fields)?;
215 Ok(())
216 }
217}
218
219#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
221#[cfg_attr(test, derive(Arbitrary))]
222pub struct CreatableTopicConfigs {
223 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
225 pub name: String,
226 #[cfg_attr(test, proptest(strategy = "proptest_strategies::optional_string()"))]
228 pub value: Option<String>,
229 pub read_only: bool,
231 pub config_source: i8,
233 pub is_sensitive: bool,
235 #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
237 pub _unknown_tagged_fields: Vec<RawTaggedField>,
238}
239
240impl Default for CreatableTopicConfigs {
241 fn default() -> Self {
242 CreatableTopicConfigs {
243 name: String::from(""),
244 value: Some(String::from("")),
245 read_only: false,
246 config_source: -1_i8,
247 is_sensitive: false,
248 _unknown_tagged_fields: Vec::new(),
249 }
250 }
251}
252
253impl CreatableTopicConfigs {
254 pub fn new<S1: AsRef<str>, S2: AsRef<str>>(name: S1, value: Option<S2>, read_only: bool, config_source: i8, is_sensitive: bool) -> Self {
255 Self {
256 name: name.as_ref().to_string(),
257 value: value.map(|s| s.as_ref().to_string()),
258 read_only,
259 config_source,
260 is_sensitive,
261 _unknown_tagged_fields: vec![],
262 }
263 }
264}
265
266#[cfg(test)]
267mod tests_creatable_topic_configs_new_and_default {
268 use super::*;
269
270 #[test]
271 fn test() {
272 let d = CreatableTopicConfigs::new(
273 String::from(""),
274 Some(String::from("")),
275 false,
276 -1_i8,
277 false,
278 );
279 assert_eq!(d, CreatableTopicConfigs::default());
280 }
281}
282
283impl Readable for CreatableTopicConfigs {
284 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
285 let name = String::read_ext(input, "name", true)?;
286 let value = Option::<String>::read_ext(input, "value", true)?;
287 let read_only = bool::read(input)?;
288 let config_source = i8::read(input)?;
289 let is_sensitive = bool::read(input)?;
290 let tagged_fields_callback = |tag: i32, _: &[u8]| {
291 match tag {
292 _ => Ok(false)
293 }
294 };
295 let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
296 Ok(CreatableTopicConfigs {
297 name, value, read_only, config_source, is_sensitive, _unknown_tagged_fields
298 })
299 }
300}
301
302impl Writable for CreatableTopicConfigs {
303 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
304 self.name.write_ext(output, "self.name", true)?;
305 self.value.write_ext(output, "self.value", true)?;
306 self.read_only.write(output)?;
307 self.config_source.write(output)?;
308 self.is_sensitive.write(output)?;
309 write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
310 Ok(())
311 }
312}
313
314#[cfg(test)]
315mod tests {
316 use super::*;
317 use proptest::prelude::*;
318
319 #[test]
320 fn test_java_default() {
321 crate::test_utils::test_java_default::<CreateTopicsResponse>("CreateTopicsResponse", 6);
322 }
323
324 proptest! {
325 #[test]
326 fn test_serde(data: CreateTopicsResponse) {
327 crate::test_utils::test_serde(&data)?;
328 }
329 }
330
331 proptest! {
332 #[test]
333 fn test_java_arbitrary(data: CreateTopicsResponse) {
334 crate::test_utils::test_java_arbitrary(&data, "CreateTopicsResponse", 6);
335 }
336 }
337}