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