Skip to main content

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