aboutsummaryrefslogtreecommitdiff
path: root/lockchain-crypto/src/databody.rs
blob: aaedce7fb1ed13d750bc76bc0458c7a92b50f3a3 (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
//!

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
    }
}