diff --git a/src/machine.rs b/src/machine.rs index 05c40f6..4f0dd1f 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -158,7 +158,27 @@ impl Machine { } } -pub type MachineDB = HashMap; +struct MachineDB { + db: lmdb::Database, +} + +impl MachineDB { + pub fn new(db: lmdb::Database) -> Self { + Self { db } + } + + pub fn get_machine(&self, txn: &T, machine_id: MachineIdentifier) + -> Result> + { + match txn.get(self.db, &machine_id.to_ne_bytes()) { + Ok(bytes) => { + Ok(Some(flexbuffers::from_slice(bytes)?)) + }, + Err(lmdb::Error::NotFound) => { Ok(None) }, + Err(e) => { Err(e.into()) }, + } + } +} pub async fn init(log: Logger, config: &Settings) -> Result { unimplemented!()