/*
wearechat - generic multiplayer game with voip
Copyright (C) 2025 metamuffin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
use crate::packets::{ReadWrite, Resource};
use anyhow::Result;
use redb::{Database, TableDefinition};
use sha2::{Digest, Sha256};
use std::{collections::HashMap, marker::PhantomData, path::Path, sync::Mutex};
const T_ENTRIES: TableDefinition<[u8; 32], &[u8]> = TableDefinition::new("e");
pub enum ResourceStore {
Redb(Database),
Memory(Mutex>>),
}
impl ResourceStore {
pub fn new_persistent(path: &Path) -> Result {
Ok(Self::Redb(Database::create(path)?))
}
pub fn new_memory() -> Self {
Self::Memory(HashMap::new().into())
}
pub fn get(&self, key: Resource) -> Result