title: Google protocol buffer messag to byte array C++
body: <p>I'm currently using two message protocols, one is google proto and the other is c-structs. What is the best solution to convert a google protocol buffer message (<code>MessageLite</code>) to a byte array?</p>
  
  <p>I want, for example, to convert the following google proto message:</p>
  
  <pre><code>message GoogleRequest
  {
       optional int32 request = 1 [default = 0];
  }
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>struct Request
  {
      int request;
  };
  </code></pre>
  
  <p>I have tried the following but it does not work:</p>
  
  <pre><code>GoogleRequest reqMsg;
  reqMsg.set_request(1234);
  
  int size = reqMsg.ByteSize();
  Request* reqStruct = new Request;
  reqMsg.SerializeToArray((void*)reqStruct , size);
  </code></pre>
  
  <p>Any suggestions, or is the best way just to do:</p>
  
  <pre><code>reqStruct-&gt;request = reqMsg.request();
  </code></pre>
  
  <p>I have a lot of message types and I would be awesome to find a generic way to do it.</p>