diff options
Diffstat (limited to 'libcmix-network/protobufclient.hpp')
| -rw-r--r-- | libcmix-network/protobufclient.hpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libcmix-network/protobufclient.hpp b/libcmix-network/protobufclient.hpp index c28c347..247b71f 100644 --- a/libcmix-network/protobufclient.hpp +++ b/libcmix-network/protobufclient.hpp @@ -6,6 +6,15 @@ #include <type_traits> +/*! + * \file + */ + +/*! + * \brief A wrapper around Client that accepts a Functor that can turn specific protobuf messages. + * in to a desired wireformat to serialize and send or receive via the Client. + * \tparam T The Protobuf functor to use when transforming messages. + */ template <typename T> class ProtobufClient : private Client { @@ -14,18 +23,31 @@ public: using Client::operator=; using Client::async_connect; - + /*! + * \brief an async_send wrapper that transforms a specific message to the container message an sends it + * \param value The specific message to send. + * \param on_sent The function to call after succesfully sending the message. + */ template<typename V, typename F> void async_send(V value, F on_sent) { typename T::proto_type m = T()(value); Client::async_send(m.SerializeAsString(), on_sent); } + /*! + * \brief an async_send wrapper, like the above but without the on_sent callback. + * \param value The specific message to send. + */ template<typename V> void async_send(V value) { async_send(value, []{}); } + /*! + * \brief An async_receive wrapper that transforms the wireformat to the protobuf + * container message type. + * \param message_handler The callback to call after receiving a message. + */ template <typename F> void async_receive(F message_handler) { auto f = [message_handler](std::vector<uint8_t> const& buffer) { |
