12 #if defined(MVSIM_HAS_ZMQ) && defined(MVSIM_HAS_PROTOBUF) 14 #include <mrpt/io/CMemoryStream.h> 15 #include <mrpt/serialization/CArchive.h> 35 void sendMessage(
const google::protobuf::MessageLite&
m, zmq::socket_t& socket);
38 zmq::message_t receiveMessage(zmq::socket_t&
s);
47 const zmq::message_t& msg, google::protobuf::MessageLite& out);
49 class UnexpectedMessageException :
public std::runtime_error
52 UnexpectedMessageException(
const char* reason) :
std::runtime_error(reason)
58 std::tuple<std::string, std::string> parseMessageToParts(
59 const zmq::message_t& msg);
61 template <
typename variant_t,
size_t IDX = 0>
62 variant_t recursiveParse(
63 const std::string& typeName,
const std::string& serializedData)
65 if constexpr (IDX < std::variant_size_v<variant_t>)
67 using this_t = std::variant_alternative_t<IDX, variant_t>;
69 const std::string expectedName = v.GetTypeName();
70 if (expectedName == typeName)
72 bool ok = v.ParseFromString(serializedData);
75 "Format error: protobuf could not decode binary message of " 81 return recursiveParse<variant_t, IDX + 1>(typeName, serializedData);
83 throw UnexpectedMessageException(
85 "Type '%s' not found in expected list of variant arguments.",
91 std::string get_zmq_endpoint(
const zmq::socket_t&
s);
98 template <
typename variant_t>
99 variant_t parseMessageVariant(
const zmq::message_t& msg)
101 const auto [typeName, serializedData] = internal::parseMessageToParts(msg);
102 return internal::recursiveParse<variant_t>(typeName, serializedData);
106 template <
class... Ts>
107 struct overloaded : Ts...
109 using Ts::operator()...;
113 template <
class... Ts>
114 overloaded(Ts...)->overloaded<Ts...>;
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1