radix_common/data/scrypto/
custom_value_kind.rs1use crate::internal_prelude::*;
2#[cfg(feature = "fuzzing")]
3use arbitrary::Arbitrary;
4
5pub const VALUE_KIND_REFERENCE: u8 = 0x80;
6pub const VALUE_KIND_OWN: u8 = 0x90;
7pub const VALUE_KIND_DECIMAL: u8 = 0xa0;
8pub const VALUE_KIND_PRECISE_DECIMAL: u8 = 0xb0;
9pub const VALUE_KIND_NON_FUNGIBLE_LOCAL_ID: u8 = 0xc0;
10
11#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
12#[cfg_attr(
13 feature = "serde",
14 derive(serde::Serialize, serde::Deserialize),
15 serde(tag = "type")
16)]
17#[derive(Copy, Debug, Clone, PartialEq, Eq, Sbor)]
18pub enum ScryptoCustomValueKind {
19 Reference,
20 Own,
21 Decimal,
22 PreciseDecimal,
23 NonFungibleLocalId,
24}
25
26impl From<ScryptoCustomValueKind> for ValueKind<ScryptoCustomValueKind> {
27 fn from(custom_value_kind: ScryptoCustomValueKind) -> Self {
28 ValueKind::Custom(custom_value_kind)
29 }
30}
31
32impl CustomValueKind for ScryptoCustomValueKind {
33 fn as_u8(&self) -> u8 {
34 match self {
35 Self::Reference => VALUE_KIND_REFERENCE,
36 Self::Own => VALUE_KIND_OWN,
37 Self::Decimal => VALUE_KIND_DECIMAL,
38 Self::PreciseDecimal => VALUE_KIND_PRECISE_DECIMAL,
39 Self::NonFungibleLocalId => VALUE_KIND_NON_FUNGIBLE_LOCAL_ID,
40 }
41 }
42
43 fn from_u8(id: u8) -> Option<Self> {
44 match id {
45 VALUE_KIND_REFERENCE => Some(ScryptoCustomValueKind::Reference),
46 VALUE_KIND_OWN => Some(ScryptoCustomValueKind::Own),
47 VALUE_KIND_DECIMAL => Some(ScryptoCustomValueKind::Decimal),
48 VALUE_KIND_PRECISE_DECIMAL => Some(ScryptoCustomValueKind::PreciseDecimal),
49 VALUE_KIND_NON_FUNGIBLE_LOCAL_ID => Some(ScryptoCustomValueKind::NonFungibleLocalId),
50 _ => None,
51 }
52 }
53}