use super::ValueId;
use crate::capnp::jeff_capnp;
use crate::reader::metadata::sealed::HasMetadataSealed;
use crate::reader::string_table::StringTable;
use crate::types::Type;
#[derive(Clone, Copy, Debug)]
pub struct WireValue<'a> {
id: ValueId,
pub(super) value_type: Type,
pub(super) metadata: capnp::struct_list::Reader<'a, jeff_capnp::meta::Owned>,
pub(super) strings: StringTable<'a>,
}
impl<'a> WireValue<'a> {
pub(crate) fn read_capnp(
id: super::ValueId,
value: jeff_capnp::value::Reader<'a>,
strings: StringTable<'a>,
) -> Self {
let value_type = value
.get_type()
.map(Type::read_capnp)
.expect("Type should be present");
let metadata = value.get_metadata().expect("Metadata should be present");
Self {
id,
value_type,
metadata,
strings,
}
}
pub fn id(&self) -> ValueId {
self.id
}
pub fn ty(&self) -> Type {
self.value_type
}
}
impl<'a> HasMetadataSealed for WireValue<'a> {
fn strings(&self) -> StringTable<'a> {
self.strings
}
fn metadata_reader(&self) -> capnp::struct_list::Reader<'a, jeff_capnp::meta::Owned> {
self.metadata
}
}