jeff/reader/value/
wire_value.rs1use super::ValueId;
4use crate::capnp::jeff_capnp;
5use crate::reader::metadata::sealed::HasMetadataSealed;
6use crate::reader::string_table::StringTable;
7
8use crate::types::Type;
9
10#[derive(Clone, Copy, Debug)]
18pub struct WireValue<'a> {
19 id: ValueId,
21 pub(super) value_type: Type,
23 pub(super) metadata: capnp::struct_list::Reader<'a, jeff_capnp::meta::Owned>,
25 pub(super) strings: StringTable<'a>,
27}
28
29impl<'a> WireValue<'a> {
30 pub(crate) fn read_capnp(
32 id: super::ValueId,
33 value: jeff_capnp::value::Reader<'a>,
34 strings: StringTable<'a>,
35 ) -> Self {
36 let value_type = value
37 .get_type()
38 .map(Type::read_capnp)
39 .expect("Type should be present");
40 let metadata = value.get_metadata().expect("Metadata should be present");
41 Self {
42 id,
43 value_type,
44 metadata,
45 strings,
46 }
47 }
48
49 pub fn id(&self) -> ValueId {
51 self.id
52 }
53
54 pub fn ty(&self) -> Type {
56 self.value_type
57 }
58}
59
60impl<'a> HasMetadataSealed for WireValue<'a> {
61 fn strings(&self) -> StringTable<'a> {
62 self.strings
63 }
64
65 fn metadata_reader(&self) -> capnp::struct_list::Reader<'a, jeff_capnp::meta::Owned> {
66 self.metadata
67 }
68}