// This file is part of bsv.
//
// bsv 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, either version 3 of the License, or (at your option)
// any later version.
//
// bsv 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 Affero GNU General Public License
// along with bsv. If not, see .
use camino::Utf8Path;
use super::err;
use super::error::{Error, Result};
use super::object_id::ObjectId;
use super::object_type::ObjectType;
use super::object_metadata::ObjectMetadata;
use super::pipeline::{Reader, Writer};
// pub struct ObjectIdIterator;
pub trait Cas {
fn object_id_from_string(&self, hex: &str) -> Result;
fn has_object_id(&self, oid: &ObjectId) -> Result;
fn iter_object_id<'s>(&'s self) -> Result>>>;
fn open_object(&self, oid: &ObjectId) -> Result<(ObjectMetadata, Box)>;
fn new_writer(&mut self, otype: &ObjectType, size: u64) -> Result>;
fn read_object(&self, oid: &ObjectId) -> Result<(ObjectMetadata, Vec)> {
let (metadata, mut reader) = self.open_object(oid)?;
let mut data = Vec::new();
reader.read_to_end(&mut data).or_else(|err|
err!("failed to read object {}: {}", oid, err))?;
let result_oid = reader.finalize()?;
if &result_oid == oid {
Ok((metadata, data))
}
else {
err!("object id mismatch: requested {}, read {}", oid, result_oid)
}
}
fn write_object(&mut self, otype: &ObjectType, data: &[u8]) -> Result {
let mut writer = self.new_writer(otype, data.len() as u64)?;
writer.write_all(data).or_else(|err|
err!("failed to write object: {}", err))?;
writer.finalize()
}
fn remove_object(&mut self, oid: &ObjectId) -> Result<()>;
}
pub trait RefStore {
fn get_ref>(&self, key: P) -> Result;
fn set_ref>(&mut self, key: P, value: &ObjectId) -> Result<()>;
fn remove_ref>(&mut self, key: P) -> Result<()>;
}