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