2022-11-11 11:55:12 +00:00
|
|
|
pub mod boundary;
|
|
|
|
pub mod domain;
|
2020-05-25 13:34:17 +00:00
|
|
|
pub mod error;
|
2022-11-11 11:55:12 +00:00
|
|
|
pub mod float;
|
2021-07-13 13:58:28 +00:00
|
|
|
pub mod hex;
|
2022-11-16 14:43:49 +00:00
|
|
|
pub mod merge;
|
2022-11-18 14:21:33 +00:00
|
|
|
pub mod packed;
|
2022-11-11 11:55:12 +00:00
|
|
|
pub mod reader;
|
|
|
|
pub mod repr;
|
2022-11-18 14:21:33 +00:00
|
|
|
pub mod shell;
|
2022-11-11 11:55:12 +00:00
|
|
|
pub mod signed_integer;
|
|
|
|
pub mod source;
|
2022-11-16 14:43:49 +00:00
|
|
|
// pub mod text;
|
2022-11-11 11:55:12 +00:00
|
|
|
pub mod types;
|
|
|
|
pub mod writer;
|
|
|
|
|
|
|
|
pub use domain::*;
|
2022-11-16 14:43:49 +00:00
|
|
|
pub use error::Error;
|
|
|
|
pub use error::ExpectedKind;
|
|
|
|
pub use merge::merge;
|
|
|
|
pub use merge::merge2;
|
2022-11-18 14:21:33 +00:00
|
|
|
pub use packed::PackedReader;
|
|
|
|
pub use packed::PackedWriter;
|
|
|
|
pub use packed::annotated_from_bytes;
|
|
|
|
pub use packed::annotated_iovalue_from_bytes;
|
|
|
|
pub use packed::from_bytes;
|
|
|
|
pub use packed::iovalue_from_bytes;
|
2022-11-11 11:55:12 +00:00
|
|
|
pub use reader::IOValues;
|
|
|
|
pub use reader::Reader;
|
2022-11-18 14:21:33 +00:00
|
|
|
pub use reader::read;
|
|
|
|
pub use reader::read_iovalue;
|
2022-11-11 11:55:12 +00:00
|
|
|
pub use repr::ValueImpl;
|
2022-11-18 14:21:33 +00:00
|
|
|
pub use repr::value_eq;
|
|
|
|
pub use repr::value_cmp;
|
|
|
|
pub use repr::value_hash;
|
|
|
|
pub use shell::Annotations;
|
|
|
|
pub use shell::Atom;
|
|
|
|
pub use shell::IOValue;
|
|
|
|
pub use shell::Map;
|
|
|
|
pub use shell::Record;
|
|
|
|
pub use shell::Set;
|
|
|
|
pub use shell::Shell;
|
|
|
|
pub use shell::ShellHandle;
|
2022-11-11 11:55:12 +00:00
|
|
|
pub use signed_integer::SignedInteger;
|
|
|
|
pub use source::BinarySource;
|
|
|
|
pub use source::BytesBinarySource;
|
|
|
|
pub use source::IOBinarySource;
|
2022-11-16 14:43:49 +00:00
|
|
|
// pub use text::TextReader;
|
|
|
|
// pub use text::TextWriter;
|
|
|
|
// pub use text::annotated_from_str;
|
|
|
|
// pub use text::annotated_iovalue_from_str;
|
|
|
|
// pub use text::from_str;
|
|
|
|
// pub use text::iovalue_from_str;
|
2022-11-11 11:55:12 +00:00
|
|
|
pub use types::AtomClass;
|
|
|
|
pub use types::CompoundClass;
|
|
|
|
pub use types::ValueClass;
|
|
|
|
pub use writer::Writer;
|
|
|
|
pub use writer::write_value;
|
2019-06-29 22:02:27 +00:00
|
|
|
|
2019-10-22 21:36:01 +00:00
|
|
|
#[cfg(test)]
|
2022-11-11 11:55:12 +00:00
|
|
|
mod demo {
|
|
|
|
use crate::*;
|
|
|
|
|
|
|
|
// fn getit<'a>(d: &'a dyn ValueImpl<NoValue>, k: &str) -> Option<&'a dyn ValueImpl<NoValue>> {
|
|
|
|
// d.get(&k)
|
|
|
|
// }
|
|
|
|
|
2022-11-16 14:43:49 +00:00
|
|
|
// #[test] fn a() {
|
|
|
|
// let l: PlainValue<NoValue> = "label".parse().unwrap();
|
|
|
|
// let r = Record::new(l.value_clone(), vec![owned(1), owned(2), owned(3)]);
|
|
|
|
// let r2 = Record::new(l, vec![owned(1), owned(2), owned(4)]);
|
2022-11-11 11:55:12 +00:00
|
|
|
|
2022-11-16 14:43:49 +00:00
|
|
|
// let mut v: Map<PlainValue<NoValue>, PlainValue<NoValue>> = Map::new();
|
|
|
|
// v.insert("\"abc\"".parse().unwrap(), "def".parse().unwrap());
|
|
|
|
// v.insert("abc".parse().unwrap(), "DEF".parse().unwrap());
|
|
|
|
// v.insert(owned(123), "xyz".parse().unwrap());
|
|
|
|
// v.insert(owned(vec![1, 2, 3]), "{a: 1, b: 2}".parse().unwrap());
|
|
|
|
// v.insert(owned(r2), "bbb".parse().unwrap());
|
|
|
|
// v.insert(owned(r), "<foo bar zot>".parse().unwrap());
|
|
|
|
// let w: &dyn ValueImpl<NoValue> = &v;
|
|
|
|
// println!("GETw abc {:?}", w.get(&"abc"));
|
|
|
|
// println!("GETw 123 {:?}", w.get(&123));
|
|
|
|
// println!("GETw qqq {:?}", w.get(&"qqq"));
|
|
|
|
// println!("GETv abc {:?}", v.get(&*value(&"abc")));
|
|
|
|
// println!("GETv 123 {:?}", v.get(&*value(&123)));
|
|
|
|
// println!("GETv qqq {:?}", v.get(&*value(&"qqq")));
|
|
|
|
// for (kk, vv) in w.entries() {
|
|
|
|
// println!("{:#?} ==> {:#?}", kk, vv);
|
|
|
|
// }
|
2022-11-11 11:55:12 +00:00
|
|
|
|
2022-11-16 14:43:49 +00:00
|
|
|
// // {
|
|
|
|
// // use std::io::BufRead;
|
|
|
|
// // for line in std::io::stdin().lock().lines() {
|
|
|
|
// // let line = line.unwrap();
|
|
|
|
// // let key = line.parse::<PlainValue<NoValue>>().unwrap();
|
|
|
|
// // let val = w.get(&key);
|
|
|
|
// // println!("{:?} == {:?} ==> {:?} == {:?}", line, &key, val, getit(&v, &line));
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
// }
|
2022-11-11 11:55:12 +00:00
|
|
|
|
2022-11-16 14:43:49 +00:00
|
|
|
// #[test] fn value_size() {
|
|
|
|
// println!("Value size {}", std::mem::size_of::<Value<'_, NoValue>>());
|
|
|
|
// println!("&dyn ValueImpl size {}", std::mem::size_of::<&dyn ValueImpl<NoValue>>());
|
|
|
|
// println!("Box dyn ValueImpl size {}", std::mem::size_of::<Box<dyn ValueImpl<NoValue>>>());
|
|
|
|
// }
|
2022-11-11 11:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test_domain {
|
2021-07-05 10:38:11 +00:00
|
|
|
use std::io;
|
2022-11-11 11:55:12 +00:00
|
|
|
use crate::*;
|
2019-10-23 21:58:36 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Hash, Clone, Ord, PartialEq, Eq, PartialOrd)]
|
|
|
|
pub enum Dom {
|
|
|
|
One,
|
|
|
|
Two,
|
|
|
|
}
|
|
|
|
|
2022-10-26 16:12:55 +00:00
|
|
|
impl Domain for Dom {
|
|
|
|
type Decode = DebugDomainCodec;
|
|
|
|
type Encode = DebugDomainCodec;
|
|
|
|
}
|
2021-01-29 12:42:17 +00:00
|
|
|
|
2022-10-26 14:00:48 +00:00
|
|
|
impl std::str::FromStr for Dom {
|
|
|
|
type Err = io::Error;
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s {
|
|
|
|
"One" => Ok(Dom::One),
|
|
|
|
"Two" => Ok(Dom::Two),
|
|
|
|
_ => Err(io::Error::new(io::ErrorKind::Other, "cannot parse preserves test domain")),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-11 11:55:12 +00:00
|
|
|
struct DomCodec;
|
2020-05-27 07:04:55 +00:00
|
|
|
|
2022-11-11 11:55:12 +00:00
|
|
|
impl DomainDecode<Dom> for DomCodec {
|
|
|
|
fn decode_embedded<'de, R: Reader<'de> + ?Sized>(
|
|
|
|
&mut self,
|
|
|
|
r: &mut R,
|
|
|
|
_read_annotations: bool,
|
|
|
|
) -> io::Result<Dom> {
|
2022-11-18 14:21:33 +00:00
|
|
|
let v = read_iovalue(r, false)?;
|
|
|
|
if v.value().as_bytestring().is_some() {
|
2022-11-11 11:55:12 +00:00
|
|
|
Ok(Dom::One)
|
|
|
|
} else {
|
|
|
|
Ok(Dom::Two)
|
|
|
|
}
|
2020-05-27 07:04:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-11 11:55:12 +00:00
|
|
|
impl DomainEncode<Dom> for DomCodec {
|
|
|
|
fn encode_embedded(
|
|
|
|
&mut self,
|
|
|
|
w: &mut dyn Writer,
|
|
|
|
d: &Dom,
|
|
|
|
) -> io::Result<()> {
|
|
|
|
match d {
|
2022-11-18 14:21:33 +00:00
|
|
|
Dom::One => Shell::from(vec![255, 255, 255, 255]).write(w, self),
|
|
|
|
Dom::Two => Shell::symbol(&format!("Dom::{:?}", d)).write(w, self),
|
2022-11-11 11:55:12 +00:00
|
|
|
}
|
2020-05-27 07:04:55 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-09 21:08:26 +00:00
|
|
|
|
2022-11-18 14:21:33 +00:00
|
|
|
fn dom_as_preserves(v: &Dom) -> io::Result<IOValue> {
|
2022-11-11 11:55:12 +00:00
|
|
|
Ok(match v {
|
2022-11-18 14:21:33 +00:00
|
|
|
Dom::One => IOValue::from(vec![255, 255, 255, 255]),
|
|
|
|
Dom::Two => IOValueImpl::symbol(format!("Dom::{:?}", v)).into(),
|
2022-11-11 11:55:12 +00:00
|
|
|
})
|
2022-10-26 14:00:48 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 11:55:12 +00:00
|
|
|
#[test] fn test_one() {
|
2022-11-18 14:21:33 +00:00
|
|
|
let v = Shell::<Dom>::from(
|
|
|
|
vec![SignedInteger::from(1).into(),
|
|
|
|
Shell::embedded(Dom::One),
|
|
|
|
SignedInteger::from(2).into()]).wrap();
|
|
|
|
assert_eq!(PackedWriter::encode_iovalue(&IOValue::copy::<Shell::<Dom>, _, _>(&v, &mut dom_as_preserves).unwrap()).unwrap(),
|
2022-11-11 11:55:12 +00:00
|
|
|
[0xb5, 0x91, 0xb2, 0x04, 255, 255, 255, 255, 0x92, 0x84]);
|
2022-10-26 14:00:48 +00:00
|
|
|
}
|
2020-05-27 07:04:55 +00:00
|
|
|
|
2022-11-11 11:55:12 +00:00
|
|
|
#[test] fn test_two() {
|
2022-11-18 14:21:33 +00:00
|
|
|
let v = Shell::<Dom>::from(
|
|
|
|
vec![SignedInteger::from(1).into(),
|
|
|
|
Shell::embedded(Dom::Two),
|
|
|
|
SignedInteger::from(2).into()]).wrap();
|
|
|
|
assert_eq!(PackedWriter::encode_iovalue(&IOValue::copy::<Shell::<Dom>, _, _>(&v, &mut dom_as_preserves).unwrap()).unwrap(),
|
2022-11-11 11:55:12 +00:00
|
|
|
[0xb5, 0x91, 0xb3, 0x08, 68, 111, 109, 58, 58, 84, 119, 111, 0x92, 0x84]);
|
2020-05-27 07:04:55 +00:00
|
|
|
}
|
|
|
|
}
|