代码之家  ›  专栏  ›  技术社区  ›  2adnielsenx xx

如何准备MSGPack在ZeroMQ基础结构上发送结构?

  •  1
  • 2adnielsenx xx  · 技术社区  · 8 年前

    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:错误:在“content”中没有名为“msgpack-pack”的成员

    如何在ZeroMQ的帮助下发送内容结构 是吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Jens Luedicke    8 年前

    你需要提供一个 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;
        }
    };
    
    }
    }
    }
    

    包()

    示例 函数(与

    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;
        }
    };
    
    推荐文章