krabka_protocol/opt/rustwide/workdir/generated/
CreateAclsResponse.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 primitives::{
7 fixed::{get_i16, get_i32, put_i16, put_i32},
8 string_bytes::{
9 compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
10 put_nullable_string,
11 },
12 string_bytes_borrowed::{
13 get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
14 },
15 },
16 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 30;
19pub const MIN_VERSION: i16 = 1;
20pub const MAX_VERSION: i16 = 3;
21pub const FLEXIBLE_MIN: i16 = 2;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25 version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq, Default)]
28pub struct CreateAclsResponse<'a> {
29 pub throttle_time_ms: i32,
30 pub results: Vec<AclCreationResult<'a>>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl CreateAclsResponse<'_> {
34 #[must_use]
38 pub fn to_owned(&self) -> crate::owned::create_acls_response::CreateAclsResponse {
39 crate::owned::create_acls_response::CreateAclsResponse {
40 throttle_time_ms: (self.throttle_time_ms),
41 results: (self.results)
42 .iter()
43 .map(AclCreationResult::to_owned)
44 .collect(),
45 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
46 }
47 }
48}
49impl Encode for CreateAclsResponse<'_> {
50 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
51 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
52 return Err(ProtocolError::UnsupportedVersion {
53 api_key: API_KEY,
54 version,
55 });
56 }
57 let flex = is_flexible(version);
58 if version >= 0 {
59 put_i32(buf, self.throttle_time_ms);
60 }
61 if version >= 0 {
62 {
63 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
64 for it in &self.results {
65 it.encode(buf, version)?;
66 }
67 };
68 }
69 if flex {
70 let tagged = WriteTaggedFields::new();
71 tagged.write(buf, &self.unknown_tagged_fields);
72 }
73 Ok(())
74 }
75 fn encoded_len(&self, version: i16) -> usize {
76 let flex = is_flexible(version);
77 let mut n: usize = 0;
78 if version >= 0 {
79 n += 4;
80 }
81 if version >= 0 {
82 n += {
83 let prefix =
84 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
85 let body: usize = (self.results)
86 .iter()
87 .map(|it| it.encoded_len(version))
88 .sum();
89 prefix + body
90 };
91 }
92 if flex {
93 let known_pairs: Vec<(u32, usize)> = Vec::new();
94 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
95 }
96 n
97 }
98}
99impl<'de> DecodeBorrow<'de> for CreateAclsResponse<'de> {
100 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
101 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
102 return Err(ProtocolError::UnsupportedVersion {
103 api_key: API_KEY,
104 version,
105 });
106 }
107 let flex = is_flexible(version);
108 let mut out = Self::default();
109 if version >= 0 {
110 out.throttle_time_ms = get_i32(buf)?;
111 }
112 if version >= 0 {
113 out.results = {
114 let n = crate::primitives::array::get_array_len(buf, flex)?;
115 let mut v = Vec::with_capacity(n);
116 for _ in 0..n {
117 v.push(AclCreationResult::decode_borrow(buf, version)?);
118 }
119 v
120 };
121 }
122 if flex {
123 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
124 }
125 Ok(out)
126 }
127}
128#[cfg(test)]
129impl CreateAclsResponse<'_> {
130 #[must_use]
131 pub fn populated(version: i16) -> Self {
132 let mut m = Self::default();
133 if version >= 0 {
134 m.throttle_time_ms = 1i32;
135 }
136 if version >= 0 {
137 m.results = vec![AclCreationResult::populated(version)];
138 }
139 m
140 }
141}
142#[derive(Debug, Clone, PartialEq, Eq)]
143pub struct AclCreationResult<'a> {
144 pub error_code: i16,
145 pub error_message: Option<&'a str>,
146 pub unknown_tagged_fields: UnknownTaggedFields,
147}
148impl Default for AclCreationResult<'_> {
149 fn default() -> Self {
150 Self {
151 error_code: 0i16,
152 error_message: Some(""),
153 unknown_tagged_fields: UnknownTaggedFields::default(),
154 }
155 }
156}
157impl AclCreationResult<'_> {
158 #[must_use]
162 pub fn to_owned(&self) -> crate::owned::create_acls_response::AclCreationResult {
163 crate::owned::create_acls_response::AclCreationResult {
164 error_code: (self.error_code),
165 error_message: (self.error_message).map(std::string::ToString::to_string),
166 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
167 }
168 }
169}
170impl Encode for AclCreationResult<'_> {
171 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
172 let flex = version >= 2;
173 if version >= 0 {
174 put_i16(buf, self.error_code);
175 }
176 if version >= 0 {
177 if flex {
178 let () = put_compact_nullable_string(buf, self.error_message);
179 } else {
180 let () = put_nullable_string(buf, self.error_message);
181 }
182 }
183 if flex {
184 let tagged = WriteTaggedFields::new();
185 tagged.write(buf, &self.unknown_tagged_fields);
186 }
187 Ok(())
188 }
189 fn encoded_len(&self, version: i16) -> usize {
190 let flex = version >= 2;
191 let mut n: usize = 0;
192 if version >= 0 {
193 n += 2;
194 }
195 if version >= 0 {
196 n += if flex {
197 compact_nullable_string_len(self.error_message)
198 } else {
199 nullable_string_len(self.error_message)
200 };
201 }
202 if flex {
203 let known_pairs: Vec<(u32, usize)> = Vec::new();
204 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
205 }
206 n
207 }
208}
209impl<'de> DecodeBorrow<'de> for AclCreationResult<'de> {
210 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
211 let flex = version >= 2;
212 let mut out = Self::default();
213 if version >= 0 {
214 out.error_code = get_i16(buf)?;
215 }
216 if version >= 0 {
217 out.error_message = if flex {
218 get_compact_nullable_string_borrowed(buf)?
219 } else {
220 get_nullable_string_borrowed(buf)?
221 };
222 }
223 if flex {
224 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
225 }
226 Ok(out)
227 }
228}
229#[cfg(test)]
230impl AclCreationResult<'_> {
231 #[must_use]
232 pub fn populated(version: i16) -> Self {
233 let mut m = Self::default();
234 if version >= 0 {
235 m.error_code = 1i16;
236 }
237 if version >= 0 {
238 m.error_message = Some("x");
239 }
240 m
241 }
242}