diff options
Diffstat (limited to 'node/nextnode.hpp')
| -rw-r--r-- | node/nextnode.hpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/node/nextnode.hpp b/node/nextnode.hpp index 6550445..9601ab5 100644 --- a/node/nextnode.hpp +++ b/node/nextnode.hpp @@ -2,6 +2,8 @@ #include "client.hpp" +#include "cmix.pb.h" + #include <boost/asio/ip/tcp.hpp> /*! @@ -9,6 +11,20 @@ */ /*! + * MESSAGE_SETTER is a boilerplate macro that generates a setter function for our CMix + * protobuf messages, This because there are seperate functions for each to type to use. + * And there seems no way to solve this using templates. + */ +#define MESSAGE_SETTER(T,F,NAME) \ +inline void message_setter(cmix_proto::CMixMessage& m, cmix_proto::T##NAME const& v) { \ + *m.mutable_##F##NAME() = v; \ +} \ + +MESSAGE_SETTER(I,i,nitialization) + +#undef MESSAGE_SETTER + +/*! * \brief The NextNode class represents the next node in the network, will only be sent to. */ class NextNode @@ -23,9 +39,14 @@ public: /*! * \brief send - * \param message is the string that is send to the next node. + * \param v The CMixMessage type we try to send and first have to wrap in a CMixMessage. */ - void send(std::string message); + template <typename T> + void send(T v) { + cmix_proto::CMixMessage m; + message_setter(m, v); + client.send(m.SerializeAsString()); + } /*! * \brief async_connect |
