aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-06-10 22:55:59 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-06-10 22:55:59 +0200
commit1449971d229c9e5ec2f2dd7589db1d65129754ec (patch)
treed01b7143cfe01190bb2e18ae130c066d263d0464
parent152be3068866a39ef355276da2f906df1cbc5568 (diff)
Adding a list type to Payload
-rw-r--r--lockchain-core/src/record.rs8
-rw-r--r--lockchain-files/src/fs.rs21
-rw-r--r--lockchain-files/src/lib.rs18
3 files changed, 36 insertions, 11 deletions
diff --git a/lockchain-core/src/record.rs b/lockchain-core/src/record.rs
index 9a30f3b..ed66f36 100644
--- a/lockchain-core/src/record.rs
+++ b/lockchain-core/src/record.rs
@@ -11,7 +11,7 @@
use chrono::{DateTime, Local};
use std::collections::BTreeMap;
-use traits::{Body, AutoEncoder};
+use traits::{AutoEncoder, Body};
/// An enum that wraps around all possible data types to store
/// as the value of a vault record.
@@ -20,10 +20,16 @@ use traits::{Body, AutoEncoder};
/// data representation itself (i.e. text, number or sub data-tree)
#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
pub enum Payload {
+ /// A simple (variable) text
Text(String),
+ /// A boolean (true, false)
Boolean(bool),
+ /// A 64bit, signed number
Number(i64),
+ /// A tree of String names, mapped to payloads
BTreeMap(BTreeMap<String, Payload>),
+ /// A list of various payloads
+ List(Vec<Payload>),
}
/// The public header of a record
diff --git a/lockchain-files/src/fs.rs b/lockchain-files/src/fs.rs
index a0c288a..7d71a82 100644
--- a/lockchain-files/src/fs.rs
+++ b/lockchain-files/src/fs.rs
@@ -20,7 +20,7 @@ pub struct Filesystem {
pub enum FileType {
/// A data record file
Record,
- /// A vault/ zser metadata file
+ /// A MetaDomain file
Metadata,
/// A simple checksum file
Checksum,
@@ -52,6 +52,7 @@ impl Filesystem {
pub fn fetch<T: AutoEncoder>(&self, types: FileType) -> Result<Vec<T>, Box<Error>> {
Ok(fs::read_dir(match types {
FileType::Record => self.root.join("records"),
+ FileType::Metadata => self.root.join("metadata"),
_ => self.root.join("."),
})?.into_iter()
.filter_map(|r| r.ok())
@@ -68,14 +69,16 @@ impl Filesystem {
}
pub fn pull<T: AutoEncoder>(&self, types: FileType, id: &str) -> Result<T, Box<Error>> {
- Ok(T::decode(&File::open(self.root.join(&format!(
- "{}.{}",
- id,
- match types {
- FileType::Record => "record",
- _ => "dat",
- }
- )))?.get_string()?)?)
+ Ok(T::decode(
+ &File::open(self.root.join(&format!(
+ "{}.{}",
+ id,
+ match types {
+ FileType::Record => "record",
+ _ => "dat",
+ }
+ )))?.get_string()?,
+ )?)
}
pub fn sync<T: AutoEncoder>(
diff --git a/lockchain-files/src/lib.rs b/lockchain-files/src/lib.rs
index eaa57c7..b9e03a0 100644
--- a/lockchain-files/src/lib.rs
+++ b/lockchain-files/src/lib.rs
@@ -6,7 +6,7 @@
extern crate lockchain_core as lcc;
use lcc::traits::{Body, Vault};
-use lcc::{Payload, Record};
+use lcc::{Payload, Record, MetaDomain};
use std::collections::HashMap;
mod fs;
@@ -86,4 +86,20 @@ impl<T: Body> Vault<T> for DataVault<T> {
fn get_data(&self, record: &str, key: &str) -> Option<&Payload> {
self.records.get(record)?.get_data(key)
}
+
+ fn meta_add_domain(&mut self, domain: &str) -> Option<()> {
+ None
+ }
+
+ fn meta_pull_domain(&mut self, domain: &str) -> Option<Vec<MetaDomain>> {
+ None
+ }
+
+ fn meta_set(&mut self, domain: &str, name: &str, data: Payload) -> Option<()> {
+ None
+ }
+
+ fn meta_get(&mut self, domain: &str, name: &str) -> Option<Payload> {
+ None
+ }
}