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

bool random; retrieve key from message

parent bcd46670
......@@ -25,12 +25,21 @@
namespace profanedb {
namespace format {
// Marshaller does the actual manipulation on Messages,
// it takes care of converting them into a message tree
// and deserialise a single message as coming from the database back to the original format
template<typename Message>
class Marshaller
{
public:
// Create the whole graph with all nested referenced messages
virtual profanedb::protobuf::MessageTreeNode Marshal(const Message & message) = 0;
// Turn a stored message back into the original format
virtual const Message & Unmarshal(const profanedb::protobuf::StorableMessage & storable) = 0;
// Retrieve the Key from the given Message
virtual const profanedb::protobuf::Key & GetKey(const Message & message) = 0;
};
}
}
......
......@@ -35,6 +35,7 @@ namespace profanedb {
namespace format {
namespace protobuf {
// TODO Loader could populate a lookup table with the Key field and other info for any given Message
// Loader is a utility class to populate a schemaPool and normalizedPool
// which profanedb::format::protobuf::Marshaller requires
class Loader
......
......@@ -158,6 +158,13 @@ const Message & Marshaller::Unmarshal(const StorableMessage & storable)
return *originalMessage;
}
// TODO Get Key from Loader without iteration
const Key & Marshaller::GetKey(const Message & message)
{
Key key;
return key;
}
void Marshaller::CopyMessage(const Message & from, Message * to)
{
std::vector< const FieldDescriptor * > setFields;
......
......@@ -49,6 +49,8 @@ public:
virtual profanedb::protobuf::MessageTreeNode Marshal(const google::protobuf::Message & message) override;
virtual const google::protobuf::Message & Unmarshal(const profanedb::protobuf::StorableMessage & storable) override;
// TODO Instead of iterating through all fields, Loader should give this info
virtual const profanedb::protobuf::Key & GetKey(const google::protobuf::Message & message) override;
private:
// Loader contains the schemaPool and normalizedPool
const std::shared_ptr<Loader> loader;
......
......@@ -52,6 +52,17 @@ INT_RANDOM_VALUE(google::protobuf::uint64);
#undef INT_RANDOM_VALUE
#define REAL_RANDOM_VALUE(TYPE) RANDOM_VALUE(TYPE, \
uniform_real_distribution<> range( \
numeric_limits< TYPE >::min(), \
numeric_limits< TYPE >::max()); \
return range(this->gen); )
REAL_RANDOM_VALUE(double);
REAL_RANDOM_VALUE(float);
#undef REAL_RANDOM_VALUE
RANDOM_VALUE(google::protobuf::string,
std::string random;
std::string chars(
......@@ -68,22 +79,10 @@ RANDOM_VALUE(google::protobuf::string,
return random;
)
#define REAL_RANDOM_VALUE(TYPE) RANDOM_VALUE(TYPE, \
uniform_real_distribution<> range( \
numeric_limits< TYPE >::min(), \
numeric_limits< TYPE >::max()); \
return range(this->gen); )
REAL_RANDOM_VALUE(double);
REAL_RANDOM_VALUE(float);
#undef REAL_RANDOM_VALUE
RANDOM_VALUE(bool,
// TODO
return true;
uniform_int_distribution<> range(0, 1);
return (bool) range(this->gen);
)
#undef RANDOM_VALUE
void RandomGenerator::FillRandomly(Message * 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