Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
UpdateFeaturesRequest.owned.rs

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