triblespace_core/value/
schemas.rs1pub mod boolean;
5pub mod ed25519;
7pub mod f256;
9pub mod f64;
11pub mod genid;
13pub mod hash;
15pub mod iu256;
17pub mod linelocation;
19pub mod r256;
21pub mod range;
23pub mod shortstring;
25pub mod time;
27
28use crate::id::ExclusiveId;
29use crate::id::Id;
30use crate::id_hex;
31use crate::macros::entity;
32use crate::metadata;
33use crate::metadata::{ConstDescribe, ConstId};
34use crate::repo::BlobStore;
35use crate::trible::Fragment;
36use crate::value::schemas::hash::Blake3;
37use crate::value::Value;
38use crate::value::ValueSchema;
39use std::convert::Infallible;
40
41pub struct UnknownValue {}
48
49impl ConstId for UnknownValue {
50 const ID: Id = id_hex!("4EC697E8599AC79D667C722E2C8BEBF4");
51}
52
53impl ConstDescribe for UnknownValue {
54 fn describe<B>(blobs: &mut B) -> Result<Fragment, B::PutError>
55 where
56 B: BlobStore<Blake3>,
57 {
58 let id = Self::ID;
59 let mut tribles = entity! {
60 ExclusiveId::force_ref(&id) @ metadata::tag: metadata::KIND_VALUE_SCHEMA
61 };
62
63 #[cfg(feature = "wasm")]
64 {
65 tribles += entity! { ExclusiveId::force_ref(&id) @
66 metadata::value_formatter: blobs.put(wasm_formatter::UNKNOWN_VALUE_WASM)?,
67 };
68 }
69 #[cfg(not(feature = "wasm"))]
70 let _ = (blobs, &mut tribles);
71 Ok(tribles)
72 }
73}
74
75#[cfg(feature = "wasm")]
76mod wasm_formatter {
77 use core::fmt::Write;
78
79 use triblespace_core_macros::value_formatter;
80
81 #[value_formatter]
82 pub(crate) fn unknown_value(raw: &[u8; 32], out: &mut impl Write) -> Result<(), u32> {
83 out.write_str("unknown:").map_err(|_| 1u32)?;
84 const TABLE: &[u8; 16] = b"0123456789ABCDEF";
85 for &byte in raw {
86 let hi = (byte >> 4) as usize;
87 let lo = (byte & 0x0F) as usize;
88 out.write_char(TABLE[hi] as char).map_err(|_| 1u32)?;
89 out.write_char(TABLE[lo] as char).map_err(|_| 1u32)?;
90 }
91 Ok(())
92 }
93}
94
95impl ValueSchema for UnknownValue {
96 type ValidationError = Infallible;
97
98 fn validate(value: Value<Self>) -> Result<Value<Self>, Self::ValidationError> {
99 Ok(value)
100 }
101}