mod function_io;
mod wire_value;
pub use function_io::FunctionIOValue;
pub use wire_value::WireValue;
use crate::capnp::jeff_capnp;
use super::string_table::StringTable;
use super::ReadError;
pub type ValueId = u32;
#[derive(Clone, Copy, Debug)]
pub struct ValueTable<'a> {
values: capnp::struct_list::Reader<'a, jeff_capnp::value::Owned>,
strings: StringTable<'a>,
}
impl<'a> ValueTable<'a> {
pub(crate) fn read_capnp(
values: capnp::struct_list::Reader<'a, jeff_capnp::value::Owned>,
strings: StringTable<'a>,
) -> Self {
Self { values, strings }
}
pub fn get(&self, idx: ValueId) -> Result<WireValue<'a>, ReadError> {
let value = self
.values
.try_get(idx)
.ok_or_else(|| ReadError::ValueOutOfBounds {
idx,
count: self.len(),
})?;
Ok(WireValue::read_capnp(idx, value, self.strings))
}
pub fn iter(&self) -> impl Iterator<Item = (ValueId, WireValue<'a>)> + '_ {
self.values.iter().enumerate().map(move |(idx, value)| {
(
idx as ValueId,
WireValue::read_capnp(idx as ValueId, value, self.strings),
)
})
}
pub fn len(&self) -> usize {
self.values.len() as usize
}
pub fn is_empty(&self) -> bool {
self.values.len() == 0
}
}