title: How to send a struct of strings using ZMQ
body: <p>I would like to compare the latency between two nodes, A and B, of a cluster by comparing the timestamp of both at the receiving node B. For this, i am utilizing a preexisting struct of integers, but with adding a string to hold the timestamp of node A.</p>
  
  <p>The struct looks like that:</p>
  
  <pre><code>struct Content {
    int id;
    double a;
    std::vector&lt;char&gt; timestamp;
  };
  </code></pre>
  
  <p>To prepare the data at node A, i am using the following:</p>
  
  <pre><code>int fEventSize = 100;
  
  Content* payload = new Content[fEventSize];
  
  boost::posix_time::ptime mst1 = boost::posix_time::microsec_clock::local_time();
  
  std::string str = to_simple_string(mst1);
  std::vector&lt;char&gt; writable(str.begin(), str.end());
  writable.push_back('\0');
  
  (&amp;payload[0])-&gt;timestamp = writable;
  </code></pre>
  
  <p>I subsequently create a ZMQ message, i memcpy payload to the message and i send it to node B as usual. To verify that the timestamp was written correctly at node A, the following works ok:</p>
  
  <pre><code>cout &lt;&lt; &amp;(&amp;payload[0])-&gt;timestamp[0]; &lt;&lt; endl;
  </code></pre>
  
  <p>But at the receiving end of node B, although i can properly print the value of the id and a members of the struct, i get a segmentation fault when i try to print the value of the timestamp:</p>
  
  <pre><code>Content* input = reinterpret_cast&lt;Content*&gt;(msg-&gt;GetData());
  
  cout &lt;&lt; "x: " &lt;&lt; (&amp;input[0])-&gt;x &lt;&lt; endl;
  
  cout &lt;&lt; "timestamp: " &lt;&lt; &amp;(&amp;input[0])-&gt;timestamp[0] &lt;&lt; endl;
  </code></pre>
  
  <p>Why is that? Is this the correct way to send struct string members using ZMQ?</p>