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 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 = 29;
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)]
24pub struct DescribeAclsRequest {
25    pub resource_type_filter: i8,
26    pub resource_name_filter: Option<String>,
27    pub pattern_type_filter: i8,
28    pub principal_filter: Option<String>,
29    pub host_filter: Option<String>,
30    pub operation: i8,
31    pub permission_type: i8,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34
35impl Default for DescribeAclsRequest {
36    fn default() -> Self {
37        Self {
38            resource_type_filter: 0i8,
39            resource_name_filter: None,
40            pattern_type_filter: 3i8,
41            principal_filter: None,
42            host_filter: None,
43            operation: 0i8,
44            permission_type: 0i8,
45            unknown_tagged_fields: Default::default(),
46        }
47    }
48}
49
50impl Encode for DescribeAclsRequest {
51    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
52        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
53            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
54        }
55        let flex = is_flexible(version);
56        if version >= 0 { put_i8(buf, self.resource_type_filter) }
57        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()) } }
58        if version >= 1 { put_i8(buf, self.pattern_type_filter) }
59        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()) } }
60        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()) } }
61        if version >= 0 { put_i8(buf, self.operation) }
62        if version >= 0 { put_i8(buf, self.permission_type) }
63        if flex {
64            let tagged = WriteTaggedFields::new();
65            tagged.write(buf, &self.unknown_tagged_fields);
66        }
67        Ok(())
68    }
69    fn encoded_len(&self, version: i16) -> usize {
70        let flex = is_flexible(version);
71        let mut n: usize = 0;
72        if version >= 0 { n += 1; }
73        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()) }; }
74        if version >= 1 { n += 1; }
75        if version >= 0 { n += if flex { compact_nullable_string_len(self.principal_filter.as_deref()) } else { nullable_string_len(self.principal_filter.as_deref()) }; }
76        if version >= 0 { n += if flex { compact_nullable_string_len(self.host_filter.as_deref()) } else { nullable_string_len(self.host_filter.as_deref()) }; }
77        if version >= 0 { n += 1; }
78        if version >= 0 { n += 1; }
79        if flex {
80            let known_pairs: Vec<(u32, usize)> = Vec::new();
81            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
82        }
83        n
84    }
85}
86
87impl<'de> Decode<'de> for DescribeAclsRequest {
88    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
89        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
90            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
91        }
92        let flex = is_flexible(version);
93        let mut out = Self::default();
94        if version >= 0 { out.resource_type_filter = get_i8(buf)?; }
95        if version >= 0 { out.resource_name_filter = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
96        if version >= 1 { out.pattern_type_filter = get_i8(buf)?; }
97        if version >= 0 { out.principal_filter = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
98        if version >= 0 { out.host_filter = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
99        if version >= 0 { out.operation = get_i8(buf)?; }
100        if version >= 0 { out.permission_type = get_i8(buf)?; }
101        if flex {
102            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
103                Ok(false)
104            })?;
105        }
106        Ok(out)
107    }
108}
109
110/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
111/// Only includes fields valid for the given version.
112#[must_use]
113#[allow(unused_comparisons)]
114pub fn default_json(version: i16) -> ::serde_json::Value {
115    let mut obj = ::serde_json::Map::new();
116    obj.insert("resourceTypeFilter".to_string(), ::serde_json::json!(0));
117    obj.insert("resourceNameFilter".to_string(), ::serde_json::Value::Null);
118    if version >= 1 {
119        obj.insert("patternTypeFilter".to_string(), ::serde_json::json!(3));
120    }
121    obj.insert("principalFilter".to_string(), ::serde_json::Value::Null);
122    obj.insert("hostFilter".to_string(), ::serde_json::Value::Null);
123    obj.insert("operation".to_string(), ::serde_json::json!(0));
124    obj.insert("permissionType".to_string(), ::serde_json::json!(0));
125    ::serde_json::Value::Object(obj)
126}
127
128impl crate::ProtocolRequest for DescribeAclsRequest {
129    const API_KEY: i16 = API_KEY;
130    const MIN_VERSION: i16 = MIN_VERSION;
131    const MAX_VERSION: i16 = MAX_VERSION;
132    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
133    type Response = super::describe_acls_response::DescribeAclsResponse;
134}