Add comments to protobuf helper methods and add protobuf to cmakelist.

This commit is contained in:
asanka-indrajith
2019-10-09 03:09:55 -04:00
parent 36f68737b1
commit 8eed642277
3 changed files with 30 additions and 0 deletions

View File

@@ -12,10 +12,13 @@ add_executable(hpcore
src/shared.cpp
src/usr/usr.cpp
src/shared.cpp
src/p2p/message.pb.cc
)
target_link_libraries(hpcore
libsodium.a
libboost_system.a
libboost_filesystem.a
pthread
protobuf.a
)

View File

@@ -19,6 +19,7 @@ void set_message(Message &message, int timestamp, string version, string publicK
bool message_serialize_to_string(Message& message, string* output)
{
//check all fields are set in message
if(message.has_publickey()
&& message.has_signature()
&& message.has_timestamp()
@@ -58,11 +59,13 @@ void set_proposal_connections(Proposal& proposal, vector<string> connections)
void set_state_patch(State& state, map<string, string> patches)
{
//state.mutable_patch().Reserve(patches.size());
//reserve memory need to optimise copy
*state.mutable_patch() = {patches.begin(), patches.end()};
}
bool proposal_serialize_to_string(Proposal& proposal, string* output)
{
//check all fields are set in the proposal
if(proposal.has_stage()
&& proposal.has_lcl()
&& proposal.has_state()
@@ -82,6 +85,9 @@ bool proposal_parse_from_string(Proposal& proposal, const string& dataString)
bool npl_serialize_to_string(NPL& npl, string* output)
{
//check all fields are set in the proposal
//not sure npl messages need both data or lcl have to be set.
//may be only one needed. need to deal with this when processing npl messages
if(npl.has_data()
&& npl.has_lcl())

View File

@@ -10,26 +10,47 @@ using namespace std;
namespace p2p
{
/*
Protobuf helpers -------------------------------------------------
Purpose of these helper methods is to wrap up protobuf functionality and provide additional functionality
such as message validation.
Need to improve and add additional functionality once started to use.
*/
//set message fields of passed of given message.
void set_message(Message &message, int timestamp, string version, string publicKey, string signature, p2p::Message::Messagetype type, string content);
// Serialize the message and store it in the given string. All message
// fields must be set.
bool message_serialize_to_string(Message& message, string* output);
// Parsing the message from binary string to given message.
bool message_parse_from_string(Message& message, const string& dataString);
//Set proposal inputs from given string vector.
void set_proposal_inputs(Proposal& proposal, vector<string> inputs);
//Set proposal outputs from given string vector.
void set_proposal_outputs(Proposal& proposal, vector<string> outputs);
//Set proposal connections from given string vector.
void set_proposal_connections(Proposal& proposal, vector<string> connections);
//Set proposal state patches from given map. Both keys and value of map should be strings.
void set_state_patch(State& state, map<string, string> patches);
// Serialize the proposal message and store it in the given string. All propsal message
// fields must be set.
bool proposal_serialize_to_string(Proposal& proposal, string* output);
// Parsing the proposal message from binary string to given message.
bool proposal_parse_from_string(Proposal& proposal, const string& dataString);
// Serialize the npl message and store it in the given string. All npl message
// fields must be set.
bool npl_serialize_to_string(NPL& npl, string* output);
// Parsing the npl message from binary string to given message.
bool npl_parse_from_string(NPL& npl, const string& dataString);
}