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