diff --git a/CMakeLists.txt b/CMakeLists.txt index 6292e4c..3f9ed57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,10 @@ add_library(libemory emory/fs/ostream.hpp emory/fs/xattr.cpp emory/fs/xattr.hpp + emory/store/bits.cpp + emory/store/bits.hpp + emory/store/repo.cpp + emory/store/repo.hpp ) target_link_libraries(libemory cruft acl) diff --git a/emory/store/bits.cpp b/emory/store/bits.cpp new file mode 100644 index 0000000..5dc2e2d --- /dev/null +++ b/emory/store/bits.cpp @@ -0,0 +1,13 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2019 Danny Robson + */ + +#include "bits.hpp" + + +/////////////////////////////////////////////////////////////////////////////// + diff --git a/emory/store/bits.hpp b/emory/store/bits.hpp new file mode 100644 index 0000000..246d204 --- /dev/null +++ b/emory/store/bits.hpp @@ -0,0 +1,67 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2019 Danny Robson + */ + +#pragma once + +#include +#include + +#include + +namespace emory::store::bits { + constexpr std::array MAGIC { 'e', 'r', '0', '0', 0x0d, 0x0a, 0x1a, 0x00, }; + + struct [[gnu::packed]] header { + u08 magic[8]; + u64 version; + struct [[gnu::packed]] { + u64 types; + u64 records; + } entries; + }; + + bool is_valid (header const&) noexcept; + + + struct [[gnu::packed]] type { + u16 system; + u16 index; + u08 count; + u08 length; + u16 reserved; + }; + + + namespace record { + struct data { + cruft::crypto::hash::SHA1::digest_t digest; + u64 first; + u64 last; + }; + } + + + constexpr u16 EMORY = 0x0000; + constexpr u16 POSIX = 0x0001; + + constexpr type DATA { + .system = EMORY, + .index = 0x0001, + .count = 0, + .length = sizeof (record::data), + .reserved = 0, + }; + + constexpr type PATH { + .system = POSIX, + .index = 0x0001, + .count = 0, + .length = 0, + .reserved = 0, + }; +}; diff --git a/emory/store/repo.cpp b/emory/store/repo.cpp new file mode 100644 index 0000000..a35fead --- /dev/null +++ b/emory/store/repo.cpp @@ -0,0 +1,15 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2019 Danny Robson + */ + +#include "repo.hpp" + + +/////////////////////////////////////////////////////////////////////////////// +struct chunker { + +}; diff --git a/emory/store/repo.hpp b/emory/store/repo.hpp new file mode 100644 index 0000000..1676b56 --- /dev/null +++ b/emory/store/repo.hpp @@ -0,0 +1,59 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2019 Danny Robson + */ + +#pragma once + +#include "bits.hpp" + +#include + +namespace emory::store { + struct repo { + repo (cruft::mapped_file &&src); + + cruft::view types (void) const; + + struct record_iterator { + using iterator_tag = std::input_iterator_tag; + using value_type = std::pair; + + record_iterator ( + cruft::view _types, + cruft::view _data + ); + + value_type operator* (void) const; + + record_iterator& operator++ (); + + bool operator== (record_iterator const&) const noexcept; + bool operator!= (record_iterator const&) const noexcept; + + private: + cruft::view m_types; + cruft::view m_data; + }; + + private: + cruft::mapped_file m_src; + }; + + + struct serialiser { + virtual ~serialiser (); + + virtual bits::type type (void) const; + virtual u64 write (cruft::posix::fd &dst, cruft::posix::fd &src); + virtual std::ostream& describe (std::ostream&) const; + }; + + + u64 send (cruft::posix::fd &dst, cruft::posix::fd &src); + + std::ostream& operator<< (std::ostream&, serialiser const&); +}