aboutsummaryrefslogtreecommitdiff
path: root/lockchain-crypto/src/databody.rs
blob: 568710c2cb62fe9c59e3d53301360423cb2c7ade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! A clear-text representation of a record body in memory
//! 
//! This form is created by the `lockchain-crypto` crate and
//! should only exist in ephemeral form. All actions are first
//! encrypted before being written back to a persistence
//! medium.

use lcc::traits::{AutoEncoder, Body};
use lcc::Payload;
use std::collections::BTreeMap;

#[derive(Serialize, Deserialize)]
pub struct DataBody {
    tree: BTreeMap<String, Payload>,
}

impl DataBody {
    pub fn new() -> Self {
        DataBody {
            tree: BTreeMap::new(),
        }
    }
}

impl AutoEncoder for DataBody {}

impl Body for DataBody {
    fn get_field(&self, key: &str) -> Option<&Payload> {
        self.tree.get(key)
    }

    fn set_field(&mut self, key: &str, value: Payload) -> Option<()> {
        self.tree.insert(key.to_owned(), value)?;
        Some(())
    }

    fn flatten(&mut self) -> Option<()> {
        None
    }
}