我试图通过ZeroMQ在节点之间进行通信。我需要发送一个struct
:
struct Content{
std::vector<cv::Mat> image;
std::string msg;
};
我尝试使用msgpack
:
Content content;
content.image = msg2;
content.mesaj = "naber kardes";
msgpack::type::tuple<Content> src(content);
// serialize the object into the buffer.
// any classes that implements
// write(const char*,size_t) can be a buffer.
std::stringstream buffer;
msgpack::pack(buffer, src);
cout << sizeof(buffer) << endl;
但它给出了:
/usr/local/include/msgpack/v1/object.hpp:631:11:错误:'内容'中没有名为'msgpack_pack'的成员
仍然是c ++的新手。
如何在msgpack
?
答案 0 :(得分:1)
您需要为pack()
结构提供 Content
功能:
namespace msgpack
{
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
{
namespace adaptor
{
template <>
struct pack<Content> {
template <typename Stream>
msgpack::packer<Stream>& operator()(
msgpack::packer<Stream>& out, Content const& obj) const
{
out.pack(obj.image);
out.pack(obj.msg);
return out;
}
};
}
}
}
如果您的软件未评估MessagePack数据,则需要根据zmq / MessagePack收件人的格式/布局预期创建 pack()功能。
convert()函数的示例(与上面 pack()函数相同的命名空间):
template <>
struct convert<Content> {
msgpack::object const& operator()(
msgpack::object const& o, Content& v) const
{
// unpack data in the same format as it was packed. see above!
return o;
}
};