kafka_wire_protocol/schema/describe_acls_response/
v3.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};
11use crate::tagged_fields::{RawTaggedField, read_tagged_fields, write_tagged_fields};
12#[cfg(test)] use crate::test_utils::proptest_strategies;
13
14/// DescribeAclsResponse, version 3.
15#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
16#[cfg_attr(test, derive(Arbitrary))]
17pub struct DescribeAclsResponse {
18    /// 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.
19    pub throttle_time_ms: i32,
20    /// The error code, or 0 if there was no error.
21    pub error_code: i16,
22    /// The error message, or null if there was no error.
23    #[cfg_attr(test, proptest(strategy = "proptest_strategies::optional_string()"))]
24    pub error_message: Option<String>,
25    /// Each Resource that is referenced in an ACL.
26    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
27    pub resources: Vec<DescribeAclsResource>,
28    /// Unknown tagged fields.
29    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
30    pub _unknown_tagged_fields: Vec<RawTaggedField>,
31}
32
33impl ApiMessage for DescribeAclsResponse {
34    fn api_key(&self) -> i16 {
35        29
36    }
37    
38    fn version(&self) -> i16 {
39        3
40    }
41}
42
43impl Response for DescribeAclsResponse { }
44
45impl Default for DescribeAclsResponse {
46    fn default() -> Self {
47        DescribeAclsResponse {
48            throttle_time_ms: 0_i32,
49            error_code: 0_i16,
50            error_message: Some(String::from("")),
51            resources: Vec::<DescribeAclsResource>::new(),
52            _unknown_tagged_fields: Vec::new(),
53        }
54    }
55}
56
57impl DescribeAclsResponse {
58    pub fn new<S1: AsRef<str>>(throttle_time_ms: i32, error_code: i16, error_message: Option<S1>, resources: Vec<DescribeAclsResource>) -> Self {
59        Self {
60            throttle_time_ms,
61            error_code,
62            error_message: error_message.map(|s| s.as_ref().to_string()),
63            resources,
64            _unknown_tagged_fields: vec![],
65        }
66    }
67}
68
69#[cfg(test)]
70mod tests_describe_acls_response_new_and_default {
71    use super::*;
72    
73    #[test]
74    fn test() {
75        let d = DescribeAclsResponse::new(
76            0_i32,
77            0_i16,
78            Some(String::from("")),
79            Vec::<DescribeAclsResource>::new(),
80        );
81        assert_eq!(d, DescribeAclsResponse::default());
82    }
83}
84
85impl Readable for DescribeAclsResponse {
86    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
87        let throttle_time_ms = i32::read(input)?;
88        let error_code = i16::read(input)?;
89        let error_message = Option::<String>::read_ext(input, "error_message", true)?;
90        let resources = read_array::<DescribeAclsResource>(input, "resources", true)?;
91        let tagged_fields_callback = |tag: i32, _: &[u8]| {
92            match tag {
93                _ => Ok(false)
94            }
95        };
96        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
97        Ok(DescribeAclsResponse {
98            throttle_time_ms, error_code, error_message, resources, _unknown_tagged_fields
99        })
100    }
101}
102
103impl Writable for DescribeAclsResponse {
104    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
105        self.throttle_time_ms.write(output)?;
106        self.error_code.write(output)?;
107        self.error_message.write_ext(output, "self.error_message", true)?;
108        write_array(output, "self.resources", &self.resources, true)?;
109        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
110        Ok(())
111    }
112}
113
114/// DescribeAclsResource, version 3.
115#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
116#[cfg_attr(test, derive(Arbitrary))]
117pub struct DescribeAclsResource {
118    /// The resource type.
119    pub resource_type: i8,
120    /// The resource name.
121    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
122    pub resource_name: String,
123    /// The resource pattern type.
124    pub pattern_type: i8,
125    /// The ACLs.
126    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
127    pub acls: Vec<AclDescription>,
128    /// Unknown tagged fields.
129    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
130    pub _unknown_tagged_fields: Vec<RawTaggedField>,
131}
132
133impl Default for DescribeAclsResource {
134    fn default() -> Self {
135        DescribeAclsResource {
136            resource_type: 0_i8,
137            resource_name: String::from(""),
138            pattern_type: 3_i8,
139            acls: Vec::<AclDescription>::new(),
140            _unknown_tagged_fields: Vec::new(),
141        }
142    }
143}
144
145impl DescribeAclsResource {
146    pub fn new<S1: AsRef<str>>(resource_type: i8, resource_name: S1, pattern_type: i8, acls: Vec<AclDescription>) -> Self {
147        Self {
148            resource_type,
149            resource_name: resource_name.as_ref().to_string(),
150            pattern_type,
151            acls,
152            _unknown_tagged_fields: vec![],
153        }
154    }
155}
156
157#[cfg(test)]
158mod tests_describe_acls_resource_new_and_default {
159    use super::*;
160    
161    #[test]
162    fn test() {
163        let d = DescribeAclsResource::new(
164            0_i8,
165            String::from(""),
166            3_i8,
167            Vec::<AclDescription>::new(),
168        );
169        assert_eq!(d, DescribeAclsResource::default());
170    }
171}
172
173impl Readable for DescribeAclsResource {
174    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
175        let resource_type = i8::read(input)?;
176        let resource_name = String::read_ext(input, "resource_name", true)?;
177        let pattern_type = i8::read(input)?;
178        let acls = read_array::<AclDescription>(input, "acls", true)?;
179        let tagged_fields_callback = |tag: i32, _: &[u8]| {
180            match tag {
181                _ => Ok(false)
182            }
183        };
184        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
185        Ok(DescribeAclsResource {
186            resource_type, resource_name, pattern_type, acls, _unknown_tagged_fields
187        })
188    }
189}
190
191impl Writable for DescribeAclsResource {
192    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
193        self.resource_type.write(output)?;
194        self.resource_name.write_ext(output, "self.resource_name", true)?;
195        self.pattern_type.write(output)?;
196        write_array(output, "self.acls", &self.acls, true)?;
197        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
198        Ok(())
199    }
200}
201
202/// AclDescription, version 3.
203#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
204#[cfg_attr(test, derive(Arbitrary))]
205pub struct AclDescription {
206    /// The ACL principal.
207    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
208    pub principal: String,
209    /// The ACL host.
210    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
211    pub host: String,
212    /// The ACL operation.
213    pub operation: i8,
214    /// The ACL permission type.
215    pub permission_type: i8,
216    /// Unknown tagged fields.
217    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
218    pub _unknown_tagged_fields: Vec<RawTaggedField>,
219}
220
221impl Default for AclDescription {
222    fn default() -> Self {
223        AclDescription {
224            principal: String::from(""),
225            host: String::from(""),
226            operation: 0_i8,
227            permission_type: 0_i8,
228            _unknown_tagged_fields: Vec::new(),
229        }
230    }
231}
232
233impl AclDescription {
234    pub fn new<S1: AsRef<str>, S2: AsRef<str>>(principal: S1, host: S2, operation: i8, permission_type: i8) -> Self {
235        Self {
236            principal: principal.as_ref().to_string(),
237            host: host.as_ref().to_string(),
238            operation,
239            permission_type,
240            _unknown_tagged_fields: vec![],
241        }
242    }
243}
244
245#[cfg(test)]
246mod tests_acl_description_new_and_default {
247    use super::*;
248    
249    #[test]
250    fn test() {
251        let d = AclDescription::new(
252            String::from(""),
253            String::from(""),
254            0_i8,
255            0_i8,
256        );
257        assert_eq!(d, AclDescription::default());
258    }
259}
260
261impl Readable for AclDescription {
262    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
263        let principal = String::read_ext(input, "principal", true)?;
264        let host = String::read_ext(input, "host", true)?;
265        let operation = i8::read(input)?;
266        let permission_type = i8::read(input)?;
267        let tagged_fields_callback = |tag: i32, _: &[u8]| {
268            match tag {
269                _ => Ok(false)
270            }
271        };
272        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
273        Ok(AclDescription {
274            principal, host, operation, permission_type, _unknown_tagged_fields
275        })
276    }
277}
278
279impl Writable for AclDescription {
280    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
281        self.principal.write_ext(output, "self.principal", true)?;
282        self.host.write_ext(output, "self.host", true)?;
283        self.operation.write(output)?;
284        self.permission_type.write(output)?;
285        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
286        Ok(())
287    }
288}
289
290#[cfg(test)]
291mod tests {
292    use super::*;
293    use proptest::prelude::*;
294    
295    #[test]
296    fn test_java_default() {
297        crate::test_utils::test_java_default::<DescribeAclsResponse>("DescribeAclsResponse", 3);
298    }
299    
300    proptest! {
301        #[test]
302        fn test_serde(data: DescribeAclsResponse) {
303            crate::test_utils::test_serde(&data)?;
304        }
305    }
306    
307    proptest! {
308        #[test]
309        fn test_java_arbitrary(data: DescribeAclsResponse) {
310            crate::test_utils::test_java_arbitrary(&data, "DescribeAclsResponse", 3);
311        }
312    }
313}