title: Sending a vector through zeromq with msgpack
body: <p>I can't seem to send a <code>vector</code> of a <code>struct</code> that I serialized with msgpack through ZeroMQ.</p>
  
  <p><strong>It's a vector of this struct:</strong></p>
  
  <pre><code>struct MyData
  {
      MyData() : id(0), x(0), y(0), a(0) {}
      MyData(const Obj &amp;r) : id(0), x(r.pose[0]), y(r.pose[1]), a(r.pose[2]) {}
      MyData(const Obj *r) : id(0), x(r-&gt;pose[0]), y(r-&gt;pose[1]), a(r-&gt;pose[2]) {}
      double id;
      double x;
      double y;
      double a;
      MSGPACK_DEFINE(id, x, y, a);
  };
  </code></pre>
  
  <p><strong>On the sending side:</strong></p>
  
  <p><code>data</code> is a <code>std::vector&lt;MyData&gt;</code></p>
  
  <pre><code>msgpack::sbuffer sbuf;
  msgpack::pack(sbuf, data);
  zmq::message_t msg(sbuf.data(), sizeof(char *) * sbuf.size(), NULL, NULL);
  local_socket-&gt;send(msg); // this is just zeromq's send function
  </code></pre>
  
  <p>Did I construct my <code>sbuffer</code> or <code>message_t</code> wrong?</p>
  
  <p><strong>On the receiving side:</strong></p>
  
  <p>I'm not sure if I was supposed to cast the <code>msg.data()</code> or not but I can't find any good documentation on how to work with ZeroMQ and messagepack.</p>
  
  <pre><code>message_t msg;
  server_socket-&gt;recv(&amp;msg);
  
  msgpack::unpacked unpacked;
  msgpack::unpack(&amp;unpacked, reinterpret_cast&lt;char*&gt;(msg.data()), msg.size());
  msgpack::object obj = unpacked.get();
  
  std::vector&lt;MyData&gt; data;
  obj.convert(&amp;data);
  printf("size %d\n", data.size());
  </code></pre>
  
  <p><strong>I get the following error:</strong></p>
  
  <blockquote>
    <p>terminate called after throwing an instance of 'msgpack::type_error'<br>
    what():  std::bad_cast Aborted</p>
  </blockquote>
  
  <p>I would appreciate any help.</p>