Commit 8915a0f2 authored by Giorgio Azzinnaro's avatar Giorgio Azzinnaro

edited Marshaller to make use of Loader

parent 90855b5c
......@@ -22,11 +22,11 @@
#include <memory>
#include <profanedb/protobuf/storage.pb.h>
#include <profanedb/format/marshaller.h>
#include <profanedb/vault/storage.h>
#include <profanedb/protobuf/storage.pb.h>
namespace profanedb {
// Db should be the main interface when embedding ProfaneDB
......
......@@ -24,8 +24,8 @@ using boost::filesystem::recursive_directory_iterator;
using boost::filesystem::symlink_option;
using google::protobuf::io::ZeroCopyInputStream;
using google::protobuf::MergedDescriptorDatabase;
using google::protobuf::compiler::SourceTreeDescriptorDatabase;
using google::protobuf::MergedDescriptorDatabase;
using google::protobuf::FileDescriptor;
using google::protobuf::FileDescriptorProto;
using google::protobuf::Descriptor;
......
......@@ -23,6 +23,7 @@
#include <profanedb/protobuf/options.pb.h>
#include <profanedb/protobuf/storage.pb.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/compiler/importer.h>
......@@ -32,6 +33,8 @@ namespace profanedb {
namespace format {
namespace protobuf {
// Loader is a utility class to populate a schemaPool and normalizedPool
// which profanedb::format::protobuf::Marshaller requires
class Loader
{
public:
......@@ -78,7 +81,11 @@ private:
google::protobuf::SimpleDescriptorDatabase normalizedDescriptorDb;
// schemaPool keeps track of the original messages
google::protobuf::DescriptorPool schemaPool;
// For each keyable message in schema, there is a normalized version
// which has Key in place of nested keyable messages
google::protobuf::DescriptorPool normalizedPool;
};
}
......
......@@ -32,11 +32,9 @@ using profanedb::protobuf::StorableMessage;
using profanedb::protobuf::Key;
profanedb::format::protobuf::Marshaller::Marshaller(
const DescriptorPool & schemaPool,
const DescriptorPool & normalizedPool,
const Loader & loader,
const Storage & storage)
: schemaPool(schemaPool)
, normalizedPool(normalizedPool)
: loader(loader)
, storage(storage)
{
}
......@@ -53,7 +51,7 @@ MessageTreeNode profanedb::format::protobuf::Marshaller::Marshal(const Message &
// replacing references to other objects with their keys.
// It will then be serialized and set as storable message payload in messageTree;
Message * normalizedMessage =
this->messageFactory.GetPrototype(normalizedPool.FindMessageTypeByName(message.GetTypeName()))->New();
this->messageFactory.GetPrototype(loader.GetNormalizedPool().FindMessageTypeByName(message.GetTypeName()))->New();
// Only fields which are set in the message are processed
std::vector< const FieldDescriptor * > setFields;
......@@ -106,11 +104,11 @@ const Message & profanedb::format::protobuf::Marshaller::Unmarshal(const Storabl
{
// An empty normalized message is generated using the Key
Message * normalizedMessage = this->messageFactory.GetPrototype(
normalizedPool.FindMessageTypeByName(storable.key().message_type()))->New();
loader.GetNormalizedPool().FindMessageTypeByName(storable.key().message_type()))->New();
// The original message is also retrieved
Message * originalMessage = this->messageFactory.GetPrototype(
schemaPool.FindMessageTypeByName(storable.key().message_type()))->New();
loader.GetSchemaPool().FindMessageTypeByName(storable.key().message_type()))->New();
// StorableMessage payload contains the serialized normalized message,
// as previously stored into the DB
......
......@@ -20,15 +20,17 @@
#ifndef PROFANEDB_FORMAT_PROTOBUF_MARSHALLER_H
#define PROFANEDB_FORMAT_PROTOBUF_MARSHALLER_H
#include <profanedb/protobuf/options.pb.h>
#include <profanedb/vault/storage.h>
#include <google/protobuf/message.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/dynamic_message.h>
#include <profanedb/protobuf/options.pb.h>
#include <profanedb/vault/storage.h>
#include <profanedb/format/marshaller.h>
#include "loader.h"
namespace profanedb {
namespace format {
namespace protobuf {
......@@ -37,8 +39,7 @@ class Marshaller : profanedb::format::Marshaller<google::protobuf::Message>
{
public:
Marshaller(
const google::protobuf::DescriptorPool & schemaPool,
const google::protobuf::DescriptorPool & normalizedPool,
const Loader & loader,
const profanedb::vault::Storage & storage
);
~Marshaller();
......@@ -47,14 +48,8 @@ public:
virtual const google::protobuf::Message & Unmarshal(const profanedb::protobuf::StorableMessage & storable) override;
private:
// TODO schemaPool, normalizedPool and CopyField are strictly related, should have their class
// schemaPool keeps track of the original messages
const google::protobuf::DescriptorPool & schemaPool;
// For each keyable message in schema, there is a normalized version
// which has Key in place of nested keyable messages
const google::protobuf::DescriptorPool & normalizedPool;
// Loader contains the schemaPool and normalizedPool
const Loader & loader;
// Because a StorableMessage only holds references to its children objects,
// Storage is used to recursively retrieve them.
......
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