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