Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i8, put_i8};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
8    string_len,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 30;
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, Default)]
24pub struct CreateAclsRequest {
25    pub creations: Vec<AclCreation>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl Encode for CreateAclsRequest {
29    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
30        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
31            return Err(ProtocolError::UnsupportedVersion {
32                api_key: API_KEY,
33                version,
34            });
35        }
36        let flex = is_flexible(version);
37        if version >= 0 {
38            {
39                crate::primitives::array::put_array_len(buf, (self.creations).len(), flex);
40                for it in &self.creations {
41                    it.encode(buf, version)?;
42                }
43            }
44        }
45        if flex {
46            let tagged = WriteTaggedFields::new();
47            tagged.write(buf, &self.unknown_tagged_fields);
48        }
49        Ok(())
50    }
51    fn encoded_len(&self, version: i16) -> usize {
52        let flex = is_flexible(version);
53        let mut n: usize = 0;
54        if version >= 0 {
55            n += {
56                let prefix =
57                    crate::primitives::array::array_len_prefix_len((self.creations).len(), flex);
58                let body: usize = (self.creations)
59                    .iter()
60                    .map(|it| it.encoded_len(version))
61                    .sum();
62                prefix + body
63            };
64        }
65        if flex {
66            let known_pairs: Vec<(u32, usize)> = Vec::new();
67            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
68        }
69        n
70    }
71}
72impl Decode<'_> for CreateAclsRequest {
73    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
74        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
75            return Err(ProtocolError::UnsupportedVersion {
76                api_key: API_KEY,
77                version,
78            });
79        }
80        let flex = is_flexible(version);
81        let mut out = Self::default();
82        if version >= 0 {
83            out.creations = {
84                let n = crate::primitives::array::get_array_len(buf, flex)?;
85                let mut v = Vec::with_capacity(n);
86                for _ in 0..n {
87                    v.push(AclCreation::decode(buf, version)?);
88                }
89                v
90            };
91        }
92        if flex {
93            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
94        }
95        Ok(out)
96    }
97}
98#[cfg(test)]
99impl CreateAclsRequest {
100    #[must_use]
101    pub fn populated(version: i16) -> Self {
102        let mut m = Self::default();
103        if version >= 0 {
104            m.creations = vec![AclCreation::populated(version)];
105        }
106        m
107    }
108}
109#[derive(Debug, Clone, PartialEq, Eq)]
110pub struct AclCreation {
111    pub resource_type: i8,
112    pub resource_name: String,
113    pub resource_pattern_type: i8,
114    pub principal: String,
115    pub host: String,
116    pub operation: i8,
117    pub permission_type: i8,
118    pub unknown_tagged_fields: UnknownTaggedFields,
119}
120impl Default for AclCreation {
121    fn default() -> Self {
122        Self {
123            resource_type: 0i8,
124            resource_name: String::new(),
125            resource_pattern_type: 3i8,
126            principal: String::new(),
127            host: String::new(),
128            operation: 0i8,
129            permission_type: 0i8,
130            unknown_tagged_fields: Default::default(),
131        }
132    }
133}
134impl Encode for AclCreation {
135    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
136        let flex = version >= 2;
137        if version >= 0 {
138            put_i8(buf, self.resource_type);
139        }
140        if version >= 0 {
141            if flex {
142                put_compact_string(buf, &self.resource_name);
143            } else {
144                put_string(buf, &self.resource_name);
145            }
146        }
147        if version >= 1 {
148            put_i8(buf, self.resource_pattern_type);
149        }
150        if version >= 0 {
151            if flex {
152                put_compact_string(buf, &self.principal);
153            } else {
154                put_string(buf, &self.principal);
155            }
156        }
157        if version >= 0 {
158            if flex {
159                put_compact_string(buf, &self.host);
160            } else {
161                put_string(buf, &self.host);
162            }
163        }
164        if version >= 0 {
165            put_i8(buf, self.operation);
166        }
167        if version >= 0 {
168            put_i8(buf, self.permission_type);
169        }
170        if flex {
171            let tagged = WriteTaggedFields::new();
172            tagged.write(buf, &self.unknown_tagged_fields);
173        }
174        Ok(())
175    }
176    fn encoded_len(&self, version: i16) -> usize {
177        let flex = version >= 2;
178        let mut n: usize = 0;
179        if version >= 0 {
180            n += 1;
181        }
182        if version >= 0 {
183            n += if flex {
184                compact_string_len(&self.resource_name)
185            } else {
186                string_len(&self.resource_name)
187            };
188        }
189        if version >= 1 {
190            n += 1;
191        }
192        if version >= 0 {
193            n += if flex {
194                compact_string_len(&self.principal)
195            } else {
196                string_len(&self.principal)
197            };
198        }
199        if version >= 0 {
200            n += if flex {
201                compact_string_len(&self.host)
202            } else {
203                string_len(&self.host)
204            };
205        }
206        if version >= 0 {
207            n += 1;
208        }
209        if version >= 0 {
210            n += 1;
211        }
212        if flex {
213            let known_pairs: Vec<(u32, usize)> = Vec::new();
214            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
215        }
216        n
217    }
218}
219impl Decode<'_> for AclCreation {
220    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
221        let flex = version >= 2;
222        let mut out = Self::default();
223        if version >= 0 {
224            out.resource_type = get_i8(buf)?;
225        }
226        if version >= 0 {
227            out.resource_name = if flex {
228                get_compact_string_owned(buf)?
229            } else {
230                get_string_owned(buf)?
231            };
232        }
233        if version >= 1 {
234            out.resource_pattern_type = get_i8(buf)?;
235        }
236        if version >= 0 {
237            out.principal = if flex {
238                get_compact_string_owned(buf)?
239            } else {
240                get_string_owned(buf)?
241            };
242        }
243        if version >= 0 {
244            out.host = if flex {
245                get_compact_string_owned(buf)?
246            } else {
247                get_string_owned(buf)?
248            };
249        }
250        if version >= 0 {
251            out.operation = get_i8(buf)?;
252        }
253        if version >= 0 {
254            out.permission_type = get_i8(buf)?;
255        }
256        if flex {
257            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
258        }
259        Ok(out)
260    }
261}
262#[cfg(test)]
263impl AclCreation {
264    #[must_use]
265    pub fn populated(version: i16) -> Self {
266        let mut m = Self::default();
267        if version >= 0 {
268            m.resource_type = 1i8;
269        }
270        if version >= 0 {
271            m.resource_name = "x".to_string();
272        }
273        if version >= 1 {
274            m.resource_pattern_type = 1i8;
275        }
276        if version >= 0 {
277            m.principal = "x".to_string();
278        }
279        if version >= 0 {
280            m.host = "x".to_string();
281        }
282        if version >= 0 {
283            m.operation = 1i8;
284        }
285        if version >= 0 {
286            m.permission_type = 1i8;
287        }
288        m
289    }
290}
291
292/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
293/// Only includes fields valid for the given version.
294#[must_use]
295#[allow(unused_comparisons)]
296pub fn default_json(version: i16) -> ::serde_json::Value {
297    let mut obj = ::serde_json::Map::new();
298    obj.insert("creations".to_string(), ::serde_json::Value::Array(vec![]));
299    ::serde_json::Value::Object(obj)
300}
301
302impl crate::ProtocolRequest for CreateAclsRequest {
303    const API_KEY: i16 = API_KEY;
304    const MIN_VERSION: i16 = MIN_VERSION;
305    const MAX_VERSION: i16 = MAX_VERSION;
306    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
307    type Response = super::create_acls_response::CreateAclsResponse;
308}