assembly_fdb_core/value/
file.rs1use crate::file::FDBFieldData;
4
5use super::{Context, UnknownValueType, Value, ValueType};
6
7#[derive(Debug, Copy, Clone, PartialEq, Eq)]
8pub struct FileContext;
10
11impl Context for FileContext {
12 type String = IndirectValue;
13 type I64 = IndirectValue;
14 type XML = IndirectValue;
15}
16
17#[derive(Debug, Copy, Clone, PartialEq, Eq)]
19pub struct IndirectValue {
20 pub addr: u32,
22}
23
24pub type FDBFieldValue = Value<FileContext>;
26
27impl TryFrom<FDBFieldData> for FDBFieldValue {
28 type Error = UnknownValueType;
29
30 fn try_from(value: FDBFieldData) -> Result<Self, Self::Error> {
31 let value_type: ValueType = value.data_type.try_into()?;
32 Ok(match value_type {
33 ValueType::Nothing => FDBFieldValue::Nothing,
34 ValueType::Integer => FDBFieldValue::Integer(i32::from_le_bytes(value.value)),
35 ValueType::Float => FDBFieldValue::Float(f32::from_le_bytes(value.value)),
36 ValueType::Text => FDBFieldValue::Text(IndirectValue {
37 addr: u32::from_le_bytes(value.value),
38 }),
39 ValueType::Boolean => FDBFieldValue::Boolean(value.value != [0; 4]),
40 ValueType::BigInt => FDBFieldValue::BigInt(IndirectValue {
41 addr: u32::from_le_bytes(value.value),
42 }),
43 ValueType::VarChar => FDBFieldValue::VarChar(IndirectValue {
44 addr: u32::from_le_bytes(value.value),
45 }),
46 })
47 }
48}