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