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