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 (MessageLite) to a byte array?
I want, for example, to convert the following google proto message:
message GoogleRequest
{
optional int32 request = 1 [default = 0];
}
to:
struct Request
{
int request;
};
I have tried the following but it does not work:
GoogleRequest reqMsg;
reqMsg.set_request(1234);
int size = reqMsg.ByteSize();
Request* reqStruct = new Request;
reqMsg.SerializeToArray((void*)reqStruct , size);
Any suggestions, or is the best way just to do:
reqStruct->request = reqMsg.request();
I have a lot of message types and I would be awesome to find a generic way to do it.