15 #ifndef SERIALBOX_CORE_ARCHIVE_BINARYARCHIVE_H 16 #define SERIALBOX_CORE_ARCHIVE_BINARYARCHIVE_H 24 #include <unordered_map> 35 static const std::string
Name;
50 using FieldTable = std::unordered_map<std::string, FieldOffsetTable>;
68 bool skipMetaData =
false);
89 const std::shared_ptr<FieldMetainfoImpl> info)
override;
92 std::shared_ptr<FieldMetainfoImpl> info)
const override;
98 virtual std::string
directory()
const override {
return directory_.string(); }
100 virtual std::string
prefix()
const override {
return prefix_; }
104 virtual std::string
metaDataFile()
const override {
return metaDatafile_.string(); }
106 virtual std::ostream&
toStream(std::ostream& stream)
const override;
108 virtual void clear()
override;
123 const std::string&
prefix);
148 const std::unique_ptr<Hash>&
hash() const noexcept {
return hash_; }
152 filesystem::path directory_;
155 filesystem::path metaDatafile_;
156 std::unique_ptr<Hash> hash_;
virtual std::string metaDataFile() const override
Full file path to the meta-data file.
virtual void clear() override
Clear the archive i.e remove all data from disk and reset the internal data-structures.
std::streamoff offset
Binary offset within the file.
static void writeToFile(std::string filename, const StorageView &storageView)
Directly write field (given by storageView) to file.
virtual std::ostream & toStream(std::ostream &stream) const override
Convert the archive to stream.
static const std::string Name
Name of the binary archive.
static void readFromFile(std::string filename, StorageView &storageView)
Directly read field (given by storageView) from file.
static const int Version
Revision of the binary archive.
virtual std::string directory() const override
Directory to write/read files.
std::vector< FileOffsetType > FieldOffsetTable
Table of ids and corresponding offsets whithin in each field (i.e file)
virtual bool isSlicedReadingSupported() const override
Indicate whether the archive supports StorageViews with attached slices.
Represent a mutable view to a multi-dimensional storage.
FieldTable & fieldTable() noexcept
Get field table.
void setHash(std::unique_ptr< Hash > hash) noexcept
Set the hash algorithm.
BinaryArchive & operator=(const BinaryArchive &)=delete
Copy assignment [deleted].
Namespace of the serialbox library.
std::string checksum
Checksum of the field.
virtual void read(StorageView &storageView, const FieldID &fieldID, std::shared_ptr< FieldMetainfoImpl > info) const override
Read the field identified by fieldID and given by storageView from disk.
Uniquely identifiy a field.
virtual std::string prefix() const override
Prefix of all files.
virtual void updateMetaData() override
Update the meta-data on disk.
virtual OpenModeKind mode() const override
Open-policy of the archive.
void readMetaDataFromJson()
Load meta-data from JSON file.
void writeMetaDataToJson()
Convert meta-data to JSON and serialize to file.
virtual bool isReadingThreadSafe() const override
Indicate whether it's safe for multiple threads to call Archive::read.
const std::unique_ptr< Hash > & hash() const noexcept
Get the hash algorithm.
void clearFieldTable()
Clear fieldTable.
std::unordered_map< std::string, FieldOffsetTable > FieldTable
Table of all fields owned by this archive, each field has a corresponding file.
Non-portable binary archive.
OpenModeKind
Policy for opening files in the Serializer and Archive.
static std::unique_ptr< Archive > create(OpenModeKind mode, const std::string &directory, const std::string &prefix)
Create a BinaryArchive.
virtual std::string name() const override
Name of the archive.
virtual FieldID write(const StorageView &storageView, const std::string &fieldID, const std::shared_ptr< FieldMetainfoImpl > info) override
Write the field given by storageView to disk.
virtual bool isWritingThreadSafe() const override
Indicate whether it's safe for multiple threads to call Archive::write.
Abstract interface for Archives.
virtual ~BinaryArchive()
Destructor.