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,
8    put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
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 { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct CreateAclsRequest {
23    pub creations: Vec<AclCreation>,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26
27impl Encode for CreateAclsRequest {
28    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
29        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
30            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
31        }
32        let flex = is_flexible(version);
33        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.creations).len(), flex); for it in &self.creations { it.encode(buf, version)?; } } }
34        if flex {
35            let tagged = WriteTaggedFields::new();
36            tagged.write(buf, &self.unknown_tagged_fields);
37        }
38        Ok(())
39    }
40    fn encoded_len(&self, version: i16) -> usize {
41        let flex = is_flexible(version);
42        let mut n: usize = 0;
43        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.creations).len(), flex); let body: usize = (self.creations).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
44        if flex {
45            let known_pairs: Vec<(u32, usize)> = Vec::new();
46            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
47        }
48        n
49    }
50}
51
52impl<'de> Decode<'de> for CreateAclsRequest {
53    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
54        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
55            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
56        }
57        let flex = is_flexible(version);
58        let mut out = Self::default();
59        if version >= 0 { out.creations = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AclCreation::decode(buf, version)?); } v }; }
60        if flex {
61            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
62                Ok(false)
63            })?;
64        }
65        Ok(out)
66    }
67}
68
69#[derive(Debug, Clone, PartialEq, Eq)]
70pub struct AclCreation {
71    pub resource_type: i8,
72    pub resource_name: String,
73    pub resource_pattern_type: i8,
74    pub principal: String,
75    pub host: String,
76    pub operation: i8,
77    pub permission_type: i8,
78    pub unknown_tagged_fields: UnknownTaggedFields,
79}
80
81impl Default for AclCreation {
82    fn default() -> Self {
83        Self {
84            resource_type: 0i8,
85            resource_name: String::new(),
86            resource_pattern_type: 3i8,
87            principal: String::new(),
88            host: String::new(),
89            operation: 0i8,
90            permission_type: 0i8,
91            unknown_tagged_fields: Default::default(),
92        }
93    }
94}
95
96impl Encode for AclCreation {
97    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
98        let flex = version >= 2;
99        if version >= 0 { put_i8(buf, self.resource_type) }
100        if version >= 0 { if flex { put_compact_string(buf, &self.resource_name) } else { put_string(buf, &self.resource_name) } }
101        if version >= 1 { put_i8(buf, self.resource_pattern_type) }
102        if version >= 0 { if flex { put_compact_string(buf, &self.principal) } else { put_string(buf, &self.principal) } }
103        if version >= 0 { if flex { put_compact_string(buf, &self.host) } else { put_string(buf, &self.host) } }
104        if version >= 0 { put_i8(buf, self.operation) }
105        if version >= 0 { put_i8(buf, self.permission_type) }
106        if flex {
107            let tagged = WriteTaggedFields::new();
108            tagged.write(buf, &self.unknown_tagged_fields);
109        }
110        Ok(())
111    }
112    fn encoded_len(&self, version: i16) -> usize {
113        let flex = version >= 2;
114        let mut n: usize = 0;
115        if version >= 0 { n += 1; }
116        if version >= 0 { n += if flex { compact_string_len(&self.resource_name) } else { string_len(&self.resource_name) }; }
117        if version >= 1 { n += 1; }
118        if version >= 0 { n += if flex { compact_string_len(&self.principal) } else { string_len(&self.principal) }; }
119        if version >= 0 { n += if flex { compact_string_len(&self.host) } else { string_len(&self.host) }; }
120        if version >= 0 { n += 1; }
121        if version >= 0 { n += 1; }
122        if flex {
123            let known_pairs: Vec<(u32, usize)> = Vec::new();
124            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
125        }
126        n
127    }
128}
129
130impl<'de> Decode<'de> for AclCreation {
131    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
132        let flex = version >= 2;
133        let mut out = Self::default();
134        if version >= 0 { out.resource_type = get_i8(buf)?; }
135        if version >= 0 { out.resource_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
136        if version >= 1 { out.resource_pattern_type = get_i8(buf)?; }
137        if version >= 0 { out.principal = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
138        if version >= 0 { out.host = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
139        if version >= 0 { out.operation = get_i8(buf)?; }
140        if version >= 0 { out.permission_type = get_i8(buf)?; }
141        if flex {
142            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
143                Ok(false)
144            })?;
145        }
146        Ok(out)
147    }
148}
149
150/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
151/// Only includes fields valid for the given version.
152#[must_use]
153#[allow(unused_comparisons)]
154pub fn default_json(version: i16) -> ::serde_json::Value {
155    let mut obj = ::serde_json::Map::new();
156    obj.insert("creations".to_string(), ::serde_json::Value::Array(vec![]));
157    ::serde_json::Value::Object(obj)
158}
159
160impl crate::ProtocolRequest for CreateAclsRequest {
161    const API_KEY: i16 = API_KEY;
162    const MIN_VERSION: i16 = MIN_VERSION;
163    const MAX_VERSION: i16 = MAX_VERSION;
164    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
165    type Response = super::create_acls_response::CreateAclsResponse;
166}