use crate::family::Family;
use crate::gid::Gid;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Value {
U(u64),
I(i64),
B(bool),
Bytes(Vec<u8>),
Str(String),
Gid(Gid),
Record(Vec<Field>),
Array(Vec<Value>),
Raw(Vec<u8>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Field {
pub tag: u8,
pub value: Value,
}
impl Field {
pub const fn new(tag: u8, value: Value) -> Field {
Field { tag, value }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Body {
Blob(Vec<u8>),
Fields(Vec<Field>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Object {
pub family: Family,
pub schemever: u8,
pub body: Body,
}
impl Object {
pub fn blob(bytes: Vec<u8>) -> Object {
Object {
family: Family::Blob,
schemever: 1,
body: Body::Blob(bytes),
}
}
pub fn fields(family: Family, body: Vec<Field>) -> Object {
Object {
family,
schemever: 1,
body: Body::Fields(body),
}
}
pub fn blob_bytes(&self) -> Option<&[u8]> {
match &self.body {
Body::Blob(b) => Some(b),
Body::Fields(_) => None,
}
}
pub fn field_sequence(&self) -> Option<&[Field]> {
match &self.body {
Body::Fields(f) => Some(f),
Body::Blob(_) => None,
}
}
}