libcryfs/implementations/inmemory/InMemoryBlock.cpp

46 lines
1.1 KiB
C++
Raw Normal View History

2015-02-17 00:23:33 +01:00
#include <messmer/blockstore/implementations/inmemory/InMemoryBlock.h>
#include <messmer/blockstore/implementations/inmemory/InMemoryBlockStore.h>
2014-12-09 17:19:59 +01:00
#include <cstring>
using std::unique_ptr;
using std::make_shared;
using std::istream;
using std::ostream;
using std::ifstream;
using std::ofstream;
using std::ios;
namespace blockstore {
namespace inmemory {
2015-01-24 22:08:41 +01:00
InMemoryBlock::InMemoryBlock(const Key &key, size_t size)
: Block(key), _data(make_shared<Data>(size)) {
2014-12-09 17:19:59 +01:00
_data->FillWithZeroes();
}
InMemoryBlock::InMemoryBlock(const InMemoryBlock &rhs)
2015-01-24 22:08:41 +01:00
: Block(rhs), _data(rhs._data) {
2014-12-09 17:19:59 +01:00
}
InMemoryBlock::~InMemoryBlock() {
}
const void *InMemoryBlock::data() const {
2014-12-09 17:19:59 +01:00
return _data->data();
}
void InMemoryBlock::write(const void *source, uint64_t offset, uint64_t size) {
assert(offset <= _data->size() && offset + size <= _data->size()); //Also check offset < _data->size() because of possible overflow in the addition
std::memcpy((uint8_t*)_data->data()+offset, source, size);
2014-12-09 17:19:59 +01:00
}
size_t InMemoryBlock::size() const {
return _data->size();
}
void InMemoryBlock::flush() {
}
}
}