krabka_protocol/opt/rustwide/workdir/generated/
UpdateFeaturesResponse.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, compact_string_len, nullable_string_len,
10 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
11 string_len,
12 },
13 string_bytes_borrowed::{
14 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
15 get_nullable_string_borrowed, get_string_borrowed,
16 },
17 },
18 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 57;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 2;
23pub const FLEXIBLE_MIN: i16 = 0;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27 version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq)]
30pub struct UpdateFeaturesResponse<'a> {
31 pub throttle_time_ms: i32,
32 pub error_code: i16,
33 pub error_message: Option<&'a str>,
34 pub results: Vec<UpdatableFeatureResult<'a>>,
35 pub unknown_tagged_fields: UnknownTaggedFields,
36}
37impl Default for UpdateFeaturesResponse<'_> {
38 fn default() -> Self {
39 Self {
40 throttle_time_ms: 0i32,
41 error_code: 0i16,
42 error_message: Some(""),
43 results: Vec::new(),
44 unknown_tagged_fields: UnknownTaggedFields::default(),
45 }
46 }
47}
48impl UpdateFeaturesResponse<'_> {
49 #[must_use]
53 pub fn to_owned(&self) -> crate::owned::update_features_response::UpdateFeaturesResponse {
54 crate::owned::update_features_response::UpdateFeaturesResponse {
55 throttle_time_ms: (self.throttle_time_ms),
56 error_code: (self.error_code),
57 error_message: (self.error_message).map(std::string::ToString::to_string),
58 results: (self.results)
59 .iter()
60 .map(UpdatableFeatureResult::to_owned)
61 .collect(),
62 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
63 }
64 }
65}
66impl Encode for UpdateFeaturesResponse<'_> {
67 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
68 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
69 return Err(ProtocolError::UnsupportedVersion {
70 api_key: API_KEY,
71 version,
72 });
73 }
74 let flex = is_flexible(version);
75 if version >= 0 {
76 put_i32(buf, self.throttle_time_ms);
77 }
78 if version >= 0 {
79 put_i16(buf, self.error_code);
80 }
81 if version >= 0 {
82 if flex {
83 let () = put_compact_nullable_string(buf, self.error_message);
84 } else {
85 let () = put_nullable_string(buf, self.error_message);
86 }
87 }
88 if (0..=1).contains(&version) {
89 {
90 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
91 for it in &self.results {
92 it.encode(buf, version)?;
93 }
94 };
95 }
96 if flex {
97 let tagged = WriteTaggedFields::new();
98 tagged.write(buf, &self.unknown_tagged_fields);
99 }
100 Ok(())
101 }
102 fn encoded_len(&self, version: i16) -> usize {
103 let flex = is_flexible(version);
104 let mut n: usize = 0;
105 if version >= 0 {
106 n += 4;
107 }
108 if version >= 0 {
109 n += 2;
110 }
111 if version >= 0 {
112 n += if flex {
113 compact_nullable_string_len(self.error_message)
114 } else {
115 nullable_string_len(self.error_message)
116 };
117 }
118 if (0..=1).contains(&version) {
119 n += {
120 let prefix =
121 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
122 let body: usize = (self.results)
123 .iter()
124 .map(|it| it.encoded_len(version))
125 .sum();
126 prefix + body
127 };
128 }
129 if flex {
130 let known_pairs: Vec<(u32, usize)> = Vec::new();
131 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
132 }
133 n
134 }
135}
136impl<'de> DecodeBorrow<'de> for UpdateFeaturesResponse<'de> {
137 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
138 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
139 return Err(ProtocolError::UnsupportedVersion {
140 api_key: API_KEY,
141 version,
142 });
143 }
144 let flex = is_flexible(version);
145 let mut out = Self::default();
146 if version >= 0 {
147 out.throttle_time_ms = get_i32(buf)?;
148 }
149 if version >= 0 {
150 out.error_code = get_i16(buf)?;
151 }
152 if version >= 0 {
153 out.error_message = if flex {
154 get_compact_nullable_string_borrowed(buf)?
155 } else {
156 get_nullable_string_borrowed(buf)?
157 };
158 }
159 if (0..=1).contains(&version) {
160 out.results = {
161 let n = crate::primitives::array::get_array_len(buf, flex)?;
162 let mut v = Vec::with_capacity(n);
163 for _ in 0..n {
164 v.push(UpdatableFeatureResult::decode_borrow(buf, version)?);
165 }
166 v
167 };
168 }
169 if flex {
170 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
171 }
172 Ok(out)
173 }
174}
175#[cfg(test)]
176impl UpdateFeaturesResponse<'_> {
177 #[must_use]
178 pub fn populated(version: i16) -> Self {
179 let mut m = Self::default();
180 if version >= 0 {
181 m.throttle_time_ms = 1i32;
182 }
183 if version >= 0 {
184 m.error_code = 1i16;
185 }
186 if version >= 0 {
187 m.error_message = Some("x");
188 }
189 if (0..=1).contains(&version) {
190 m.results = vec![UpdatableFeatureResult::populated(version)];
191 }
192 m
193 }
194}
195#[derive(Debug, Clone, PartialEq, Eq)]
196pub struct UpdatableFeatureResult<'a> {
197 pub feature: &'a str,
198 pub error_code: i16,
199 pub error_message: Option<&'a str>,
200 pub unknown_tagged_fields: UnknownTaggedFields,
201}
202impl Default for UpdatableFeatureResult<'_> {
203 fn default() -> Self {
204 Self {
205 feature: "",
206 error_code: 0i16,
207 error_message: Some(""),
208 unknown_tagged_fields: UnknownTaggedFields::default(),
209 }
210 }
211}
212impl UpdatableFeatureResult<'_> {
213 #[must_use]
217 pub fn to_owned(&self) -> crate::owned::update_features_response::UpdatableFeatureResult {
218 crate::owned::update_features_response::UpdatableFeatureResult {
219 feature: (self.feature).to_string(),
220 error_code: (self.error_code),
221 error_message: (self.error_message).map(std::string::ToString::to_string),
222 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
223 }
224 }
225}
226impl Encode for UpdatableFeatureResult<'_> {
227 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
228 let flex = version >= 0;
229 if version >= 0 {
230 if flex {
231 let () = put_compact_string(buf, self.feature);
232 } else {
233 let () = put_string(buf, self.feature);
234 }
235 }
236 if version >= 0 {
237 put_i16(buf, self.error_code);
238 }
239 if version >= 0 {
240 if flex {
241 let () = put_compact_nullable_string(buf, self.error_message);
242 } else {
243 let () = put_nullable_string(buf, self.error_message);
244 }
245 }
246 if flex {
247 let tagged = WriteTaggedFields::new();
248 tagged.write(buf, &self.unknown_tagged_fields);
249 }
250 Ok(())
251 }
252 fn encoded_len(&self, version: i16) -> usize {
253 let flex = version >= 0;
254 let mut n: usize = 0;
255 if version >= 0 {
256 n += if flex {
257 compact_string_len(self.feature)
258 } else {
259 string_len(self.feature)
260 };
261 }
262 if version >= 0 {
263 n += 2;
264 }
265 if version >= 0 {
266 n += if flex {
267 compact_nullable_string_len(self.error_message)
268 } else {
269 nullable_string_len(self.error_message)
270 };
271 }
272 if flex {
273 let known_pairs: Vec<(u32, usize)> = Vec::new();
274 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
275 }
276 n
277 }
278}
279impl<'de> DecodeBorrow<'de> for UpdatableFeatureResult<'de> {
280 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
281 let flex = version >= 0;
282 let mut out = Self::default();
283 if version >= 0 {
284 out.feature = if flex {
285 get_compact_string_borrowed(buf)?
286 } else {
287 get_string_borrowed(buf)?
288 };
289 }
290 if version >= 0 {
291 out.error_code = get_i16(buf)?;
292 }
293 if version >= 0 {
294 out.error_message = if flex {
295 get_compact_nullable_string_borrowed(buf)?
296 } else {
297 get_nullable_string_borrowed(buf)?
298 };
299 }
300 if flex {
301 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
302 }
303 Ok(out)
304 }
305}
306#[cfg(test)]
307impl UpdatableFeatureResult<'_> {
308 #[must_use]
309 pub fn populated(version: i16) -> Self {
310 let mut m = Self::default();
311 if version >= 0 {
312 m.feature = "x";
313 }
314 if version >= 0 {
315 m.error_code = 1i16;
316 }
317 if version >= 0 {
318 m.error_message = Some("x");
319 }
320 m
321 }
322}