Move ObjectType to core.

This commit is contained in:
2020-09-27 14:12:20 +02:00
parent d992fb3eb9
commit 82ea603ba4
7 changed files with 31 additions and 11 deletions

View File

@@ -17,6 +17,7 @@
pub mod error; pub mod error;
pub mod config; pub mod config;
pub mod object_id; pub mod object_id;
pub mod object;
pub mod repository; pub mod repository;
@@ -27,4 +28,5 @@ pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");
pub use error::{Error, Result, ErrorKind}; pub use error::{Error, Result, ErrorKind};
pub use config::{Config, RepositoryConfig}; pub use config::{Config, RepositoryConfig};
pub use object_id::ObjectId; pub use object_id::ObjectId;
pub use object::{ObjectType, OTYPE_BLOB, OTYPE_TREE};
pub use repository::Repository; pub use repository::Repository;

20
libbsv/src/core/object.rs Normal file
View File

@@ -0,0 +1,20 @@
// 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.
//
// cdb 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 cdb. If not, see <https://www.gnu.org/licenses/>.
pub type ObjectType = [u8; 4];
pub const OTYPE_BLOB: &ObjectType = b"blob";
pub const OTYPE_TREE: &ObjectType = b"tree";

View File

@@ -25,6 +25,8 @@ pub mod simple_db;
pub use crate::core::{ pub use crate::core::{
Error, Result, ErrorKind, Error, Result, ErrorKind,
Config, RepositoryConfig, Config, RepositoryConfig,
ObjectId, ObjectId, ObjectType,
Repository, Repository,
OTYPE_BLOB, OTYPE_TREE,
}; };

View File

@@ -20,6 +20,5 @@ pub mod object;
pub use simple_db::SimpleDb; pub use simple_db::SimpleDb;
pub use object::{ pub use object::{
OTYPE_BLOB, OTYPE_TREE,
ObjectReader, ObjectReader,
}; };

View File

@@ -30,12 +30,7 @@ use flate2::{
use crate::core::error::*; use crate::core::error::*;
use crate::core::ObjectId; use crate::core::ObjectId;
use crate::core::ObjectType;
pub type ObjectType = [u8; 4];
pub const OTYPE_BLOB: &ObjectType = b"blob";
pub const OTYPE_TREE: &ObjectType = b"tree";
pub struct ObjectWriter<W: Write, D: Digest> { pub struct ObjectWriter<W: Write, D: Digest> {
@@ -190,6 +185,8 @@ impl<T: Read + Seek> WriteAsObject for T {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::core::OTYPE_BLOB;
use super::*; use super::*;
const PAYLOAD: &[u8; 12] = b"Hello World!"; const PAYLOAD: &[u8; 12] = b"Hello World!";

View File

@@ -24,10 +24,10 @@ use tempfile::{NamedTempFile};
use crate::core::error::*; use crate::core::error::*;
use crate::core::ObjectId; use crate::core::ObjectId;
use crate::core::{ObjectType, OTYPE_BLOB};
use super::object::{ use super::object::{
OTYPE_BLOB, ObjectReader, WriteAsObject,
ObjectReader, ObjectType, WriteAsObject,
}; };

View File

@@ -27,8 +27,8 @@ use tempfile::{TempDir};
use libbsv::{ use libbsv::{
Result, Result,
ObjectId, ObjectId,
simple_db::{
OTYPE_BLOB, OTYPE_BLOB,
simple_db::{
SimpleDb, SimpleDb,
} }
}; };