Skip to main content

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