use std::fmt::{Display, Formatter};
use strum::IntoStaticStr;
#[derive(PartialEq, Debug, IntoStaticStr)]
pub enum Value {
Null(()),
Bool(bool),
U8(u8),
I16(i16),
I32(i32),
Currency(i64),
F32(f32),
F64(f64),
DateTime(u64),
Binary(Box<Vec<u8>>),
Text(Box<String>),
LargeBinary(Box<Vec<u8>>),
LargeText(Box<String>),
SuperLarge(Box<Vec<u8>>),
U32(u32),
I64(i64),
Guid(Box<Vec<u8>>),
U16(u16),
Long(Box<Vec<u8>>),
Multi(Vec<Self>),
}
impl Value {
pub fn type_name(&self) -> &'static str {
self.into()
}
}
impl Eq for Value {}
impl From<libesedb::Value> for Value {
fn from(value: libesedb::Value) -> Self {
match value {
libesedb::Value::Null(_) => Self::Null(()),
libesedb::Value::Bool(v) => Self::Bool(v),
libesedb::Value::U8(v) => Self::U8(v),
libesedb::Value::I16(v) => Self::I16(v),
libesedb::Value::I32(v) => Self::I32(v),
libesedb::Value::Currency(v) => Self::Currency(v),
libesedb::Value::F32(v) => Self::F32(v),
libesedb::Value::F64(v) => Self::F64(v),
libesedb::Value::DateTime(v) => Self::DateTime(v),
libesedb::Value::Binary(v) => Self::Binary(Box::new(Vec::from(&v[..]))),
libesedb::Value::Text(v) => Self::Text(Box::new(v)),
libesedb::Value::LargeBinary(v) => Self::LargeBinary(Box::new(Vec::from(&v[..]))),
libesedb::Value::LargeText(v) => Self::LargeText(Box::new(v)),
libesedb::Value::SuperLarge(v) => Self::SuperLarge(Box::new(Vec::from(&v[..]))),
libesedb::Value::U32(v) => Self::U32(v),
libesedb::Value::I64(v) => Self::I64(v),
libesedb::Value::Guid(v) => Self::Guid(Box::new(Vec::from(&v[..]))),
libesedb::Value::U16(v) => Self::U16(v),
v => unimplemented!("unable to convert {v:?}"),
}
}
}
impl Display for Value {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Value::Null(_) => write!(f, ""),
Value::Bool(v) => write!(f, "{v}"),
Value::U8(v) => write!(f, "{v}"),
Value::I16(v) => write!(f, "{v}"),
Value::I32(v) => write!(f, "{v}"),
Value::Currency(v) => write!(f, "{v}"),
Value::F32(v) => write!(f, "{v}"),
Value::F64(v) => write!(f, "{v}"),
Value::DateTime(v) => write!(f, "{v}"),
Value::Binary(v) => write!(f, "{v:?}"),
Value::Text(v) => write!(f, "{v}"),
Value::LargeBinary(v) => write!(f, "{v:?}"),
Value::LargeText(v) => write!(f, "{v}"),
Value::SuperLarge(v) => write!(f, "{v:?}"),
Value::U32(v) => write!(f, "{v}"),
Value::I64(v) => write!(f, "{v}"),
Value::Guid(v) => write!(f, "{v:?}"),
Value::U16(v) => write!(f, "{v}"),
Value::Long(v) => write!(f, "{v:?}"),
Value::Multi(multi) => {
let values: Vec<_> = multi.iter().map(|v| format!("{v}")).collect();
write!(f, "[{}]", values.join(","))
}
}
}
}