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