Commit 9de5bd29 authored by Giorgio Azzinnaro's avatar Giorgio Azzinnaro

debugging

parent 438d8852
......@@ -68,6 +68,15 @@ Loader::Loader(
, schemaPool(new MergedDescriptorDatabase(&includeDb, &schemaDb), &errorCollector)
, normalizedPool(new MergedDescriptorDatabase(&includeDb, &normalizedDescriptorDb), &errorCollector)
{
// profanedb.protobuf.options.key is defined in here
// It is used to mark the primary key on Messages
const FileDescriptor * optionsFile = schemaPool.FindFileByName("profanedb/protobuf/options.proto");
FileDescriptorProto optionsProto;
optionsFile->CopyTo(&optionsProto);
normalizedDescriptorDb.AddAndOwn(&optionsProto);
BOOST_LOG_TRIVIAL(debug) << "Loading profanedb/protobuf/options.proto and copying to normalized descriptor db";
// Just in case schema is defined in more than one place
for (const auto & path: schemaSourceTree->paths) {
......@@ -82,11 +91,13 @@ Loader::Loader(
// The file is now retrieved, and its path for Protobuf must be relative to the mapping
// it's parsed, normalized (nested keyable messages are removed)
FileDescriptorProto normalizedProto = this->ParseFile(schemaPool.FindFileByName(file.path().lexically_relative(path).string()));
FileDescriptorProto normalizedProto = this->ParseFile(
schemaPool.FindFileByName(file.path().lexically_relative(path).string()));
BOOST_LOG_TRIVIAL(debug) << "Adding normalized proto " << normalizedProto.name();
// The normalizedDescriptorDb keeps these new Descriptors
normalizedDescriptorDb.AddAndOwn(&normalizedProto);
normalizedPool.FindFileByName(normalizedProto.name());
}
}
}
......@@ -160,22 +171,13 @@ bool Loader::IsKeyable(const Descriptor * descriptor) const
return false;
}
const DescriptorPool & Loader::GetSchemaPool() const
{
return this->schemaPool;
}
const DescriptorPool & Loader::GetNormalizedPool() const
const DescriptorPool & Loader::GetPool(PoolType poolType) const
{
return this->normalizedPool;
return (poolType == SCHEMA) ? this->schemaPool : this->normalizedPool;
}
const Descriptor * Loader::GetDescriptor(PoolType poolType, std::string typeName) const
{
const DescriptorPool & pool = ((poolType == SCHEMA)
? this->schemaPool
: this->normalizedPool);
BOOST_LOG_TRIVIAL(debug) << "Getting descriptor "
<< typeName
<< " from "
......@@ -184,7 +186,7 @@ const Descriptor * Loader::GetDescriptor(PoolType poolType, std::string typeName
: "NORMALIZED")
<< " pool";
const Descriptor * descriptor = pool.FindMessageTypeByName(typeName);
const Descriptor * descriptor = this->GetPool(poolType).FindMessageTypeByName(typeName);
if (descriptor == NULL)
throw std::runtime_error(typeName + " doesn't exist");
......
......@@ -59,15 +59,15 @@ public:
Loader(
std::unique_ptr<RootSourceTree> include,
std::unique_ptr<RootSourceTree> schema);
const google::protobuf::DescriptorPool & GetSchemaPool() const;
const google::protobuf::DescriptorPool & GetNormalizedPool() const;
enum PoolType {
SCHEMA,
NORMALIZED
};
// Get either Schema or Normalized pool
const google::protobuf::DescriptorPool & GetPool(PoolType poolType) const;
// Retrieve a Descriptor either from Schema or Normalized pool
const google::protobuf::Descriptor * GetDescriptor(
PoolType poolType,
......
......@@ -18,7 +18,8 @@ using google::protobuf::Message;
struct Format
{
std::shared_ptr<Marshaller<Message>> marshaller;
std::shared_ptr<Loader> loader;
std::shared_ptr<ProtobufMarshaller> marshaller;
Format()
{
......@@ -35,15 +36,20 @@ struct Format
auto schemaSourceTree = new Loader::RootSourceTree{"/home/giorgio/Documents/ProfaneDB/ProfaneDB/test/profanedb/test/protobuf/schema"};
auto loader = std::make_shared<Loader>(
this->loader = std::make_shared<Loader>(
std::unique_ptr<Loader::RootSourceTree>(includeSourceTree),
std::unique_ptr<Loader::RootSourceTree>(schemaSourceTree));
std::unique_ptr<Loader::RootSourceTree>(schemaSourceTree));
this->marshaller = std::make_shared<ProtobufMarshaller>(storage, loader);
}
};
BOOST_FIXTURE_TEST_CASE(first, Format)
BOOST_FIXTURE_TEST_CASE(load, Format)
{
loader->GetPool(Loader::SCHEMA).FindFileByName("test.proto");
}
BOOST_FIXTURE_TEST_CASE(marshal, Format)
{
schema::Test message;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment