Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i16, put_i16};
4use crate::primitives::string_bytes::{
5    compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
6    string_len,
7};
8use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
9use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
10use bytes::{Buf, BufMut};
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 0;
13pub const FLEXIBLE_MIN: i16 = 0;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct FeatureLevelRecord {
20    pub name: String,
21    pub feature_level: i16,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl Encode for FeatureLevelRecord {
25    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
26        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
27            return Err(ProtocolError::SchemaMismatch(
28                "FeatureLevelRecord version out of range",
29            ));
30        }
31        let flex = is_flexible(version);
32        if version >= 0 {
33            if flex {
34                put_compact_string(buf, &self.name);
35            } else {
36                put_string(buf, &self.name);
37            }
38        }
39        if version >= 0 {
40            put_i16(buf, self.feature_level);
41        }
42        if flex {
43            let tagged = WriteTaggedFields::new();
44            tagged.write(buf, &self.unknown_tagged_fields);
45        }
46        Ok(())
47    }
48    fn encoded_len(&self, version: i16) -> usize {
49        let flex = is_flexible(version);
50        let mut n: usize = 0;
51        if version >= 0 {
52            n += if flex {
53                compact_string_len(&self.name)
54            } else {
55                string_len(&self.name)
56            };
57        }
58        if version >= 0 {
59            n += 2;
60        }
61        if flex {
62            let known_pairs: Vec<(u32, usize)> = Vec::new();
63            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
64        }
65        n
66    }
67}
68impl Decode<'_> for FeatureLevelRecord {
69    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
70        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
71            return Err(ProtocolError::SchemaMismatch(
72                "FeatureLevelRecord version out of range",
73            ));
74        }
75        let flex = is_flexible(version);
76        let mut out = Self::default();
77        if version >= 0 {
78            out.name = if flex {
79                get_compact_string_owned(buf)?
80            } else {
81                get_string_owned(buf)?
82            };
83        }
84        if version >= 0 {
85            out.feature_level = get_i16(buf)?;
86        }
87        if flex {
88            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
89        }
90        Ok(out)
91    }
92}
93#[cfg(test)]
94impl FeatureLevelRecord {
95    #[must_use]
96    pub fn populated(version: i16) -> Self {
97        let mut m = Self::default();
98        if version >= 0 {
99            m.name = "x".to_string();
100        }
101        if version >= 0 {
102            m.feature_level = 1i16;
103        }
104        m
105    }
106}
107/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
108/// Only includes fields valid for the given version.
109#[must_use]
110#[allow(unused_comparisons)]
111pub fn default_json(version: i16) -> ::serde_json::Value {
112    let mut obj = ::serde_json::Map::new();
113    obj.insert(
114        "name".to_string(),
115        ::serde_json::Value::String(String::new()),
116    );
117    obj.insert("featureLevel".to_string(), ::serde_json::json!(0));
118    ::serde_json::Value::Object(obj)
119}