@@ -7,35 +7,57 @@ use graph::prelude::*;
77use std:: io:: { self , Read , Write } ;
88use std:: str:: FromStr ;
99
10+ /// Canonical TLV value tag bytes.
11+ ///
12+ /// These are the single source of truth for the tag byte of each `Value`
13+ /// variant on the wire. They match the table in
14+ /// `docs/rust-abi-spec.md` section 4.6 one-for-one. Changing any value in
15+ /// this module is a breaking ABI change and requires an `apiVersion` bump.
16+ pub mod tags {
17+ pub const NULL : u8 = 0x00 ;
18+ pub const STRING : u8 = 0x01 ;
19+ pub const INT : u8 = 0x02 ;
20+ pub const INT8 : u8 = 0x03 ;
21+ pub const BIG_INT : u8 = 0x04 ;
22+ pub const BIG_DECIMAL : u8 = 0x05 ;
23+ pub const BOOL : u8 = 0x06 ;
24+ pub const BYTES : u8 = 0x07 ;
25+ pub const ADDRESS : u8 = 0x08 ;
26+ pub const ARRAY : u8 = 0x09 ;
27+ }
28+
1029/// Value type tags for TLV serialization.
30+ ///
31+ /// Discriminants are pulled from the [`tags`] module so there is a single
32+ /// authoritative definition of each on-wire byte.
1133#[ repr( u8 ) ]
1234#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
1335pub enum ValueTag {
14- Null = 0x00 ,
15- String = 0x01 ,
16- Int = 0x02 ,
17- Int8 = 0x03 ,
18- BigInt = 0x04 ,
19- BigDecimal = 0x05 ,
20- Bool = 0x06 ,
21- Bytes = 0x07 ,
22- Address = 0x08 ,
23- Array = 0x09 ,
36+ Null = tags :: NULL ,
37+ String = tags :: STRING ,
38+ Int = tags :: INT ,
39+ Int8 = tags :: INT8 ,
40+ BigInt = tags :: BIG_INT ,
41+ BigDecimal = tags :: BIG_DECIMAL ,
42+ Bool = tags :: BOOL ,
43+ Bytes = tags :: BYTES ,
44+ Address = tags :: ADDRESS ,
45+ Array = tags :: ARRAY ,
2446}
2547
2648impl ValueTag {
2749 pub fn from_u8 ( v : u8 ) -> Option < Self > {
2850 match v {
29- 0x00 => Some ( Self :: Null ) ,
30- 0x01 => Some ( Self :: String ) ,
31- 0x02 => Some ( Self :: Int ) ,
32- 0x03 => Some ( Self :: Int8 ) ,
33- 0x04 => Some ( Self :: BigInt ) ,
34- 0x05 => Some ( Self :: BigDecimal ) ,
35- 0x06 => Some ( Self :: Bool ) ,
36- 0x07 => Some ( Self :: Bytes ) ,
37- 0x08 => Some ( Self :: Address ) ,
38- 0x09 => Some ( Self :: Array ) ,
51+ tags :: NULL => Some ( Self :: Null ) ,
52+ tags :: STRING => Some ( Self :: String ) ,
53+ tags :: INT => Some ( Self :: Int ) ,
54+ tags :: INT8 => Some ( Self :: Int8 ) ,
55+ tags :: BIG_INT => Some ( Self :: BigInt ) ,
56+ tags :: BIG_DECIMAL => Some ( Self :: BigDecimal ) ,
57+ tags :: BOOL => Some ( Self :: Bool ) ,
58+ tags :: BYTES => Some ( Self :: Bytes ) ,
59+ tags :: ADDRESS => Some ( Self :: Address ) ,
60+ tags :: ARRAY => Some ( Self :: Array ) ,
3961 _ => None ,
4062 }
4163 }
0 commit comments