Skip to main content

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

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