BlobStorage: more code review fixes.

This commit is contained in:
Yury Melnichek 2012-09-25 19:37:18 +02:00 committed by Alex Zolotarev
parent 122429fbf2
commit 1aabac1393
2 changed files with 14 additions and 6 deletions

View file

@ -36,21 +36,24 @@ BlobStorage::~BlobStorage()
void BlobStorage::Init()
{
string header(3, ' ');
ReadFromPos(*m_pReader, 0, &header[0], 3);
uint32_t const HEADER_TAG_SIZE = 3;
uint32_t const HEADER_SIZE = 4;
string header(HEADER_TAG_SIZE, ' ');
ReadFromPos(*m_pReader, 0, &header[0], HEADER_TAG_SIZE);
if (header != "Blb")
MYTHROW(BlobStorage::OpenException, (header));
m_bitsInChunkSize = ReadPrimitiveFromPos<uint8_t>(*m_pReader, 3);
m_bitsInChunkSize = ReadPrimitiveFromPos<uint8_t>(*m_pReader, HEADER_TAG_SIZE);
uint64_t const fileSize = m_pReader->Size();
uint32_t const blobCount = ReadPrimitiveFromPos<uint32_t>(*m_pReader, fileSize - 4);
uint32_t const blobCount = ReadPrimitiveFromPos<uint32_t>(*m_pReader, fileSize - HEADER_SIZE);
m_blobInfo.Init(PolymorphReader(m_pReader->CreateSubReader(
fileSize - 4 - 4 * blobCount,
fileSize - HEADER_SIZE - 4 * blobCount,
4 * blobCount)));
uint32_t const chunkCount =
(blobCount > 0 ? (m_blobInfo[blobCount - 1] >> m_bitsInChunkSize) + 1 : 0);
m_chunkOffset.Init(PolymorphReader(m_pReader->CreateSubReader(
fileSize - 4 - 4 * blobCount - 4 * chunkCount,
fileSize - HEADER_SIZE - 4 * blobCount - 4 * chunkCount,
4 * chunkCount)));
}

View file

@ -4,6 +4,7 @@
#include "../base/assert.hpp"
#include "../base/base.hpp"
#include "../base/exception.hpp"
#include "../base/src_point.hpp"
#include "../std/type_traits.hpp"
@ -23,6 +24,8 @@ public:
typedef TDifference difference_type;
typedef TReader ReaderType;
DECLARE_EXCEPTION(OpenException, RootException);
DDVector() : m_Size(0) {}
explicit DDVector(TReader const & reader) : m_reader(reader)
@ -163,6 +166,8 @@ public:
private:
void InitSize()
{
if ((m_reader.Size() % sizeof(T)) != 0)
MYTHROW(OpenException, (m_reader.Size(), sizeof(T)));
// TODO: Check that reader.Size() % sizeof(T) == 0
m_Size = m_reader.Size() / sizeof(T);
}