Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
UpdateFeaturesResponse.owned.rs

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