Skip to main content

triblespace_core/blob/
schemas.rs

1//! This is a collection of Rust types that can be (de)serialized as [crate::prelude::Blob]s.
2
3/// Raw file bytes blob schema.
4pub mod filebytes;
5/// Arbitrary-length UTF-8 text blob schema.
6pub mod longstring;
7/// Canonical trible sequence blob schema.
8pub mod simplearchive;
9/// Succinct (Ring-based) compressed trible archive blob schema.
10pub mod succinctarchive;
11/// WebAssembly bytecode blob schema.
12pub mod wasmcode;
13
14use anybytes::Bytes;
15
16use crate::blob::BlobSchema;
17use crate::id::Id;
18use crate::id_hex;
19use crate::metadata::{ConstDescribe, ConstId};
20
21use super::Blob;
22use super::ToBlob;
23use super::TryFromBlob;
24
25/// A blob schema for an unknown blob.
26/// This blob schema is used as a fallback when the blob schema is not known.
27/// It is not recommended to use this blob schema in practice.
28/// Instead, use a specific blob schema.
29///
30/// Any bit pattern can be a valid blob of this schema.
31pub struct UnknownBlob;
32impl BlobSchema for UnknownBlob {}
33
34impl ConstId for UnknownBlob {
35    const ID: Id = id_hex!("EAB14005141181B0C10C4B5DD7985F8D");
36}
37
38impl ConstDescribe for UnknownBlob {}
39
40impl TryFromBlob<UnknownBlob> for Bytes {
41    type Error = std::convert::Infallible;
42
43    fn try_from_blob(blob: Blob<UnknownBlob>) -> Result<Self, Self::Error> {
44        Ok(blob.bytes)
45    }
46}
47
48impl ToBlob<UnknownBlob> for Bytes {
49    fn to_blob(self) -> Blob<UnknownBlob> {
50        Blob::new(self)
51    }
52}