Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeAclsRequest.owned.rs

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