Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DeleteAclsResponse.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_i16, get_i32, get_i8, put_i16, put_i32, 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 DeleteAclsResponse {
25    pub throttle_time_ms: i32,
26    pub filter_results: Vec<DeleteAclsFilterResult>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl Encode for DeleteAclsResponse {
31    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
34        }
35        let flex = is_flexible(version);
36        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
37        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.filter_results).len(), flex); for it in &self.filter_results { it.encode(buf, version)?; } } }
38        if flex {
39            let tagged = WriteTaggedFields::new();
40            tagged.write(buf, &self.unknown_tagged_fields);
41        }
42        Ok(())
43    }
44    fn encoded_len(&self, version: i16) -> usize {
45        let flex = is_flexible(version);
46        let mut n: usize = 0;
47        if version >= 0 { n += 4; }
48        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.filter_results).len(), flex); let body: usize = (self.filter_results).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
49        if flex {
50            let known_pairs: Vec<(u32, usize)> = Vec::new();
51            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
52        }
53        n
54    }
55}
56
57impl<'de> Decode<'de> for DeleteAclsResponse {
58    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
59        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
60            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
61        }
62        let flex = is_flexible(version);
63        let mut out = Self::default();
64        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
65        if version >= 0 { out.filter_results = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DeleteAclsFilterResult::decode(buf, version)?); } v }; }
66        if flex {
67            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
68                Ok(false)
69            })?;
70        }
71        Ok(out)
72    }
73}
74
75#[derive(Debug, Clone, PartialEq, Eq, Default)]
76pub struct DeleteAclsFilterResult {
77    pub error_code: i16,
78    pub error_message: Option<String>,
79    pub matching_acls: Vec<DeleteAclsMatchingAcl>,
80    pub unknown_tagged_fields: UnknownTaggedFields,
81}
82
83impl Encode for DeleteAclsFilterResult {
84    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
85        let flex = version >= 2;
86        if version >= 0 { put_i16(buf, self.error_code) }
87        if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
88        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.matching_acls).len(), flex); for it in &self.matching_acls { it.encode(buf, version)?; } } }
89        if flex {
90            let tagged = WriteTaggedFields::new();
91            tagged.write(buf, &self.unknown_tagged_fields);
92        }
93        Ok(())
94    }
95    fn encoded_len(&self, version: i16) -> usize {
96        let flex = version >= 2;
97        let mut n: usize = 0;
98        if version >= 0 { n += 2; }
99        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
100        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.matching_acls).len(), flex); let body: usize = (self.matching_acls).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
101        if flex {
102            let known_pairs: Vec<(u32, usize)> = Vec::new();
103            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
104        }
105        n
106    }
107}
108
109impl<'de> Decode<'de> for DeleteAclsFilterResult {
110    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
111        let flex = version >= 2;
112        let mut out = Self::default();
113        if version >= 0 { out.error_code = get_i16(buf)?; }
114        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
115        if version >= 0 { out.matching_acls = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DeleteAclsMatchingAcl::decode(buf, version)?); } v }; }
116        if flex {
117            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
118                Ok(false)
119            })?;
120        }
121        Ok(out)
122    }
123}
124
125#[derive(Debug, Clone, PartialEq, Eq)]
126pub struct DeleteAclsMatchingAcl {
127    pub error_code: i16,
128    pub error_message: Option<String>,
129    pub resource_type: i8,
130    pub resource_name: String,
131    pub pattern_type: i8,
132    pub principal: String,
133    pub host: String,
134    pub operation: i8,
135    pub permission_type: i8,
136    pub unknown_tagged_fields: UnknownTaggedFields,
137}
138
139impl Default for DeleteAclsMatchingAcl {
140    fn default() -> Self {
141        Self {
142            error_code: 0i16,
143            error_message: None,
144            resource_type: 0i8,
145            resource_name: String::new(),
146            pattern_type: 3i8,
147            principal: String::new(),
148            host: String::new(),
149            operation: 0i8,
150            permission_type: 0i8,
151            unknown_tagged_fields: Default::default(),
152        }
153    }
154}
155
156impl Encode for DeleteAclsMatchingAcl {
157    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
158        let flex = version >= 2;
159        if version >= 0 { put_i16(buf, self.error_code) }
160        if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
161        if version >= 0 { put_i8(buf, self.resource_type) }
162        if version >= 0 { if flex { put_compact_string(buf, &self.resource_name) } else { put_string(buf, &self.resource_name) } }
163        if version >= 1 { put_i8(buf, self.pattern_type) }
164        if version >= 0 { if flex { put_compact_string(buf, &self.principal) } else { put_string(buf, &self.principal) } }
165        if version >= 0 { if flex { put_compact_string(buf, &self.host) } else { put_string(buf, &self.host) } }
166        if version >= 0 { put_i8(buf, self.operation) }
167        if version >= 0 { put_i8(buf, self.permission_type) }
168        if flex {
169            let tagged = WriteTaggedFields::new();
170            tagged.write(buf, &self.unknown_tagged_fields);
171        }
172        Ok(())
173    }
174    fn encoded_len(&self, version: i16) -> usize {
175        let flex = version >= 2;
176        let mut n: usize = 0;
177        if version >= 0 { n += 2; }
178        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
179        if version >= 0 { n += 1; }
180        if version >= 0 { n += if flex { compact_string_len(&self.resource_name) } else { string_len(&self.resource_name) }; }
181        if version >= 1 { n += 1; }
182        if version >= 0 { n += if flex { compact_string_len(&self.principal) } else { string_len(&self.principal) }; }
183        if version >= 0 { n += if flex { compact_string_len(&self.host) } else { string_len(&self.host) }; }
184        if version >= 0 { n += 1; }
185        if version >= 0 { n += 1; }
186        if flex {
187            let known_pairs: Vec<(u32, usize)> = Vec::new();
188            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
189        }
190        n
191    }
192}
193
194impl<'de> Decode<'de> for DeleteAclsMatchingAcl {
195    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
196        let flex = version >= 2;
197        let mut out = Self::default();
198        if version >= 0 { out.error_code = get_i16(buf)?; }
199        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
200        if version >= 0 { out.resource_type = get_i8(buf)?; }
201        if version >= 0 { out.resource_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
202        if version >= 1 { out.pattern_type = get_i8(buf)?; }
203        if version >= 0 { out.principal = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
204        if version >= 0 { out.host = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
205        if version >= 0 { out.operation = get_i8(buf)?; }
206        if version >= 0 { out.permission_type = get_i8(buf)?; }
207        if flex {
208            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
209                Ok(false)
210            })?;
211        }
212        Ok(out)
213    }
214}
215
216/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
217/// Only includes fields valid for the given version.
218#[must_use]
219#[allow(unused_comparisons)]
220pub fn default_json(version: i16) -> ::serde_json::Value {
221    let mut obj = ::serde_json::Map::new();
222    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
223    obj.insert("filterResults".to_string(), ::serde_json::Value::Array(vec![]));
224    ::serde_json::Value::Object(obj)
225}