11use num_enum:: { IntoPrimitive , TryFromPrimitive } ;
22use std:: io;
3- use value:: PropertyValueEnum ;
43
5- use super :: ParseError ;
4+ use super :: Error ;
65
76pub mod value;
7+ pub use value:: PropertyValueEnum ;
88
99#[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
1010#[ derive(
@@ -45,22 +45,23 @@ pub enum BinPropertyKind {
4545}
4646
4747impl BinPropertyKind {
48+ /// Converts a u8 into a BinPropertyKind, accounting for pre/post WadChunkLink.
49+ ///
4850 /// The WadChunkLink bin property type was newly added by Riot. For some reason they decided to put it in the middle of the enum,
4951 /// so we need to handle cases from before and after it existed.
5052 ///
5153 /// "Legacy" property types need to be fudged around to pretend like WadChunkLink always existed, from our pov.
5254 ///
5355 /// "Non-legacy" property types can just be used as is.
5456 ///
55- pub fn unpack ( raw : u8 , legacy : bool ) -> Result < BinPropertyKind , ParseError > {
57+ pub fn unpack ( raw : u8 , legacy : bool ) -> Result < BinPropertyKind , Error > {
5658 use BinPropertyKind as BPK ;
5759 if !legacy {
58- // TODO (alan): don't panic here
5960 return Ok ( BPK :: try_from_primitive ( raw) ?) ;
6061 }
6162 let mut fudged = raw;
6263
63- // if the prop type comes after where WadChunkLink is now, we need to
64+ // if the prop type comes after where WadChunkLink is now, we need to fudge it
6465 if fudged >= BPK :: WadChunkLink . into ( ) && fudged < BPK :: Container . into ( ) {
6566 fudged -= Into :: < u8 > :: into ( BPK :: WadChunkLink ) ;
6667 fudged |= Into :: < u8 > :: into ( BPK :: Container ) ;
@@ -73,6 +74,7 @@ impl BinPropertyKind {
7374 Ok ( BinPropertyKind :: try_from_primitive ( fudged) ?)
7475 }
7576
77+ /// Whether this property kind is a primitive type. (i8, u8, .. u32, u64, f32, Vector2, Vector3, Vector4, Matrix44, Color, String, Hash, WadChunkLink),
7678 pub fn is_primitive ( & self ) -> bool {
7779 use BinPropertyKind :: * ;
7880 matches ! (
@@ -98,6 +100,7 @@ impl BinPropertyKind {
98100 )
99101 }
100102
103+ /// Whether this property kind is a container type (container, unordered container, optional, map).
101104 pub fn is_container ( & self ) -> bool {
102105 use BinPropertyKind :: * ;
103106 matches ! ( self , Container | UnorderedContainer | Optional | Map )
@@ -107,7 +110,7 @@ impl BinPropertyKind {
107110 self ,
108111 reader : & mut R ,
109112 legacy : bool ,
110- ) -> Result < PropertyValueEnum , super :: ParseError > {
113+ ) -> Result < PropertyValueEnum , super :: Error > {
111114 PropertyValueEnum :: from_reader ( reader, self , legacy)
112115 }
113116}
@@ -122,10 +125,11 @@ pub struct BinProperty {
122125
123126use super :: traits:: PropertyValue as _;
124127impl BinProperty {
128+ /// Read a BinProperty from a reader. This will read the name_hash, prop kind and then value, in that order.
125129 pub fn from_reader < R : io:: Read + std:: io:: Seek + ?Sized > (
126130 reader : & mut R ,
127131 legacy : bool ,
128- ) -> Result < Self , ParseError > {
132+ ) -> Result < Self , Error > {
129133 use super :: traits:: ReaderExt ;
130134 use byteorder:: { ReadBytesExt as _, LE } ;
131135 let name_hash = reader. read_u32 :: < LE > ( ) ?;
0 commit comments