crabka_protocol/opt/rustwide/workdir/generated/
DescribeAclsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i8, put_i8};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, get_compact_nullable_string_owned, get_nullable_string_owned,
8 nullable_string_len, put_compact_nullable_string, put_nullable_string,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 29;
14pub const MIN_VERSION: i16 = 1;
15pub const MAX_VERSION: i16 = 3;
16pub const FLEXIBLE_MIN: i16 = 2;
17
18#[inline]
19fn is_flexible(version: i16) -> bool {
20 version >= FLEXIBLE_MIN
21}
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct DescribeAclsRequest {
25 pub resource_type_filter: i8,
26 pub resource_name_filter: Option<String>,
27 pub pattern_type_filter: i8,
28 pub principal_filter: Option<String>,
29 pub host_filter: Option<String>,
30 pub operation: i8,
31 pub permission_type: i8,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Default for DescribeAclsRequest {
35 fn default() -> Self {
36 Self {
37 resource_type_filter: 0i8,
38 resource_name_filter: None,
39 pattern_type_filter: 3i8,
40 principal_filter: None,
41 host_filter: None,
42 operation: 0i8,
43 permission_type: 0i8,
44 unknown_tagged_fields: Default::default(),
45 }
46 }
47}
48impl Encode for DescribeAclsRequest {
49 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
50 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
51 return Err(ProtocolError::UnsupportedVersion {
52 api_key: API_KEY,
53 version,
54 });
55 }
56 let flex = is_flexible(version);
57 if version >= 0 {
58 put_i8(buf, self.resource_type_filter);
59 }
60 if version >= 0 {
61 if flex {
62 put_compact_nullable_string(buf, self.resource_name_filter.as_deref());
63 } else {
64 put_nullable_string(buf, self.resource_name_filter.as_deref());
65 }
66 }
67 if version >= 1 {
68 put_i8(buf, self.pattern_type_filter);
69 }
70 if version >= 0 {
71 if flex {
72 put_compact_nullable_string(buf, self.principal_filter.as_deref());
73 } else {
74 put_nullable_string(buf, self.principal_filter.as_deref());
75 }
76 }
77 if version >= 0 {
78 if flex {
79 put_compact_nullable_string(buf, self.host_filter.as_deref());
80 } else {
81 put_nullable_string(buf, self.host_filter.as_deref());
82 }
83 }
84 if version >= 0 {
85 put_i8(buf, self.operation);
86 }
87 if version >= 0 {
88 put_i8(buf, self.permission_type);
89 }
90 if flex {
91 let tagged = WriteTaggedFields::new();
92 tagged.write(buf, &self.unknown_tagged_fields);
93 }
94 Ok(())
95 }
96 fn encoded_len(&self, version: i16) -> usize {
97 let flex = is_flexible(version);
98 let mut n: usize = 0;
99 if version >= 0 {
100 n += 1;
101 }
102 if version >= 0 {
103 n += if flex {
104 compact_nullable_string_len(self.resource_name_filter.as_deref())
105 } else {
106 nullable_string_len(self.resource_name_filter.as_deref())
107 };
108 }
109 if version >= 1 {
110 n += 1;
111 }
112 if version >= 0 {
113 n += if flex {
114 compact_nullable_string_len(self.principal_filter.as_deref())
115 } else {
116 nullable_string_len(self.principal_filter.as_deref())
117 };
118 }
119 if version >= 0 {
120 n += if flex {
121 compact_nullable_string_len(self.host_filter.as_deref())
122 } else {
123 nullable_string_len(self.host_filter.as_deref())
124 };
125 }
126 if version >= 0 {
127 n += 1;
128 }
129 if version >= 0 {
130 n += 1;
131 }
132 if flex {
133 let known_pairs: Vec<(u32, usize)> = Vec::new();
134 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
135 }
136 n
137 }
138}
139impl Decode<'_> for DescribeAclsRequest {
140 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
141 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
142 return Err(ProtocolError::UnsupportedVersion {
143 api_key: API_KEY,
144 version,
145 });
146 }
147 let flex = is_flexible(version);
148 let mut out = Self::default();
149 if version >= 0 {
150 out.resource_type_filter = get_i8(buf)?;
151 }
152 if version >= 0 {
153 out.resource_name_filter = if flex {
154 get_compact_nullable_string_owned(buf)?
155 } else {
156 get_nullable_string_owned(buf)?
157 };
158 }
159 if version >= 1 {
160 out.pattern_type_filter = get_i8(buf)?;
161 }
162 if version >= 0 {
163 out.principal_filter = if flex {
164 get_compact_nullable_string_owned(buf)?
165 } else {
166 get_nullable_string_owned(buf)?
167 };
168 }
169 if version >= 0 {
170 out.host_filter = if flex {
171 get_compact_nullable_string_owned(buf)?
172 } else {
173 get_nullable_string_owned(buf)?
174 };
175 }
176 if version >= 0 {
177 out.operation = get_i8(buf)?;
178 }
179 if version >= 0 {
180 out.permission_type = get_i8(buf)?;
181 }
182 if flex {
183 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
184 }
185 Ok(out)
186 }
187}
188#[cfg(test)]
189impl DescribeAclsRequest {
190 #[must_use]
191 pub fn populated(version: i16) -> Self {
192 let mut m = Self::default();
193 if version >= 0 {
194 m.resource_type_filter = 1i8;
195 }
196 if version >= 0 {
197 m.resource_name_filter = Some("x".to_string());
198 }
199 if version >= 1 {
200 m.pattern_type_filter = 1i8;
201 }
202 if version >= 0 {
203 m.principal_filter = Some("x".to_string());
204 }
205 if version >= 0 {
206 m.host_filter = Some("x".to_string());
207 }
208 if version >= 0 {
209 m.operation = 1i8;
210 }
211 if version >= 0 {
212 m.permission_type = 1i8;
213 }
214 m
215 }
216}
217
218#[must_use]
221#[allow(unused_comparisons)]
222pub fn default_json(version: i16) -> ::serde_json::Value {
223 let mut obj = ::serde_json::Map::new();
224 obj.insert("resourceTypeFilter".to_string(), ::serde_json::json!(0));
225 obj.insert("resourceNameFilter".to_string(), ::serde_json::Value::Null);
226 if version >= 1 {
227 obj.insert("patternTypeFilter".to_string(), ::serde_json::json!(3));
228 }
229 obj.insert("principalFilter".to_string(), ::serde_json::Value::Null);
230 obj.insert("hostFilter".to_string(), ::serde_json::Value::Null);
231 obj.insert("operation".to_string(), ::serde_json::json!(0));
232 obj.insert("permissionType".to_string(), ::serde_json::json!(0));
233 ::serde_json::Value::Object(obj)
234}
235
236impl crate::ProtocolRequest for DescribeAclsRequest {
237 const API_KEY: i16 = API_KEY;
238 const MIN_VERSION: i16 = MIN_VERSION;
239 const MAX_VERSION: i16 = MAX_VERSION;
240 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
241 type Response = super::describe_acls_response::DescribeAclsResponse;
242}