kafka_wire_protocol/schema/create_partitions_response/
v2.rs1use 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};
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 CreatePartitionsResponse {
18 pub throttle_time_ms: i32,
20 #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
22 pub results: Vec<CreatePartitionsTopicResult>,
23 #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
25 pub _unknown_tagged_fields: Vec<RawTaggedField>,
26}
27
28impl ApiMessage for CreatePartitionsResponse {
29 fn api_key(&self) -> i16 {
30 37
31 }
32
33 fn version(&self) -> i16 {
34 2
35 }
36}
37
38impl Response for CreatePartitionsResponse { }
39
40impl Default for CreatePartitionsResponse {
41 fn default() -> Self {
42 CreatePartitionsResponse {
43 throttle_time_ms: 0_i32,
44 results: Vec::<CreatePartitionsTopicResult>::new(),
45 _unknown_tagged_fields: Vec::new(),
46 }
47 }
48}
49
50impl CreatePartitionsResponse {
51 pub fn new(throttle_time_ms: i32, results: Vec<CreatePartitionsTopicResult>) -> Self {
52 Self {
53 throttle_time_ms,
54 results,
55 _unknown_tagged_fields: vec![],
56 }
57 }
58}
59
60#[cfg(test)]
61mod tests_create_partitions_response_new_and_default {
62 use super::*;
63
64 #[test]
65 fn test() {
66 let d = CreatePartitionsResponse::new(
67 0_i32,
68 Vec::<CreatePartitionsTopicResult>::new(),
69 );
70 assert_eq!(d, CreatePartitionsResponse::default());
71 }
72}
73
74impl Readable for CreatePartitionsResponse {
75 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
76 let throttle_time_ms = i32::read(input)?;
77 let results = read_array::<CreatePartitionsTopicResult>(input, "results", 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(CreatePartitionsResponse {
85 throttle_time_ms, results, _unknown_tagged_fields
86 })
87 }
88}
89
90impl Writable for CreatePartitionsResponse {
91 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
92 self.throttle_time_ms.write(output)?;
93 write_array(output, "self.results", &self.results, 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 CreatePartitionsTopicResult {
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 #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
113 pub _unknown_tagged_fields: Vec<RawTaggedField>,
114}
115
116impl Default for CreatePartitionsTopicResult {
117 fn default() -> Self {
118 CreatePartitionsTopicResult {
119 name: String::from(""),
120 error_code: 0_i16,
121 error_message: None,
122 _unknown_tagged_fields: Vec::new(),
123 }
124 }
125}
126
127impl CreatePartitionsTopicResult {
128 pub fn new<S1: AsRef<str>, S2: AsRef<str>>(name: S1, error_code: i16, error_message: Option<S2>) -> Self {
129 Self {
130 name: name.as_ref().to_string(),
131 error_code,
132 error_message: error_message.map(|s| s.as_ref().to_string()),
133 _unknown_tagged_fields: vec![],
134 }
135 }
136}
137
138#[cfg(test)]
139mod tests_create_partitions_topic_result_new_and_default {
140 use super::*;
141
142 #[test]
143 fn test() {
144 let d = CreatePartitionsTopicResult::new(
145 String::from(""),
146 0_i16,
147 None::<String>,
148 );
149 assert_eq!(d, CreatePartitionsTopicResult::default());
150 }
151}
152
153impl Readable for CreatePartitionsTopicResult {
154 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
155 let name = String::read_ext(input, "name", true)?;
156 let error_code = i16::read(input)?;
157 let error_message = Option::<String>::read_ext(input, "error_message", true)?;
158 let tagged_fields_callback = |tag: i32, _: &[u8]| {
159 match tag {
160 _ => Ok(false)
161 }
162 };
163 let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
164 Ok(CreatePartitionsTopicResult {
165 name, error_code, error_message, _unknown_tagged_fields
166 })
167 }
168}
169
170impl Writable for CreatePartitionsTopicResult {
171 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
172 self.name.write_ext(output, "self.name", true)?;
173 self.error_code.write(output)?;
174 self.error_message.write_ext(output, "self.error_message", true)?;
175 write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
176 Ok(())
177 }
178}
179
180#[cfg(test)]
181mod tests {
182 use super::*;
183 use proptest::prelude::*;
184
185 #[test]
186 fn test_java_default() {
187 crate::test_utils::test_java_default::<CreatePartitionsResponse>("CreatePartitionsResponse", 2);
188 }
189
190 proptest! {
191 #[test]
192 fn test_serde(data: CreatePartitionsResponse) {
193 crate::test_utils::test_serde(&data)?;
194 }
195 }
196
197 proptest! {
198 #[test]
199 fn test_java_arbitrary(data: CreatePartitionsResponse) {
200 crate::test_utils::test_java_arbitrary(&data, "CreatePartitionsResponse", 2);
201 }
202 }
203}