diff --git a/src/structure/tfc/datatypes.rs b/src/structure/tfc/datatypes.rs index a9b11234..a94ed689 100644 --- a/src/structure/tfc/datatypes.rs +++ b/src/structure/tfc/datatypes.rs @@ -176,6 +176,12 @@ impl TdbDataType for u32 { } } +impl FromLexical for u32 { + fn from_lexical(b: B) -> Self { + b.reader().read_u16::().unwrap() as u32 + } +} + impl FromLexical for u32 { fn from_lexical(b: B) -> Self { b.reader().read_u32::().unwrap() @@ -244,6 +250,18 @@ impl TdbDataType for i32 { } } +impl FromLexical for i32 { + fn from_lexical(b: B) -> Self { + b.reader().read_i16::().unwrap() as i32 + } +} + +impl FromLexical for i32 { + fn from_lexical(b: B) -> Self { + b.reader().read_u16::().unwrap() as i32 + } +} + impl FromLexical for i32 { fn from_lexical(b: B) -> Self { let i = b.reader().read_u32::().unwrap(); @@ -251,6 +269,30 @@ impl FromLexical for i32 { } } +impl ToLexical for i32 { + fn to_lexical(&self) -> Bytes { + >::to_lexical(&self as &i32) + } +} + +impl ToLexical for i32 { + fn to_lexical(&self) -> Bytes { + >::to_lexical(&self as &i32) + } +} + +impl ToLexical for i32 { + fn to_lexical(&self) -> Bytes { + >::to_lexical(&self as &i32) + } +} + +impl ToLexical for i32 { + fn to_lexical(&self) -> Bytes { + >::to_lexical(&self as &i32) + } +} + impl ToLexical for i32 { fn to_lexical(&self) -> Bytes { let sign_flip = I32_BYTE_MASK ^ (*self as u32); diff --git a/src/structure/tfc/typed.rs b/src/structure/tfc/typed.rs index 2494d07d..002943be 100644 --- a/src/structure/tfc/typed.rs +++ b/src/structure/tfc/typed.rs @@ -39,6 +39,22 @@ impl TypedDictEntry { T::from_lexical(self.entry.as_buf()) } + pub fn as_casted_val + TdbDataType + FromLexical>(&self) -> T { + assert_eq!(Q::datatype(), self.datatype); + Q::from_lexical(self.entry.as_buf()).into() + } + + pub fn as_i32(&self) -> Option { + match self.datatype { + Datatype::Int32 => Some(self.as_casted_val::()), + Datatype::UInt8 => Some(self.as_casted_val::()), + Datatype::Int8 => Some(self.as_casted_val::()), + Datatype::UInt16 => Some(self.as_casted_val::()), + Datatype::Int16 => Some(self.as_casted_val::()), + _ => None, + } + } + pub fn datatype(&self) -> Datatype { self.datatype }