0

I am having the message as

Package letters;
message A
{
    message Aa
    {
        // fields
    }
    message Aaa
    {
        // fields
    }
    repeated Aa AaMessage = 1;
    repeated Aaa AaaMessage = 2;
}
message B
{
    message Bb
    {
        // fields
    }
    message Bbb
    {
        // fields
    }
    repeated Bb BbMessage = 1;
    repeated Bbb BbbMessage = 2;
}

message alphabet
{
    repeated A MessageA = 1;
    repeated B MessageB = 2;
}

I have complied the proto file using CPP_OUT. No problem in compiling and serializing the message. I have got the message serialized by using SerializeToString() as..

letters::alphabet letterMessage;
letters::A* aMessageFields = letterMessage->add_messagea();
letters::Aa* aaMessageFields = aMessageFields->add_aamessage();

    // set some default values for all fields in message

std::string SerializedMessage;
letterMessage.SerializeToString(&SerializedMessage);

I am also having the JSON serialised message in another std::wstring. I need to pass these two messages as a single value meaning single message. So I tried to concatenate both the string type protobuffer serialized value and the std::wstring JSON serialised value and store the result string in std::string. I have tried many ways. nothing works. :(

std::string SerializedMessage;
std::wstring JSONserializedMessage;
std::string completeMessage;
completeMessage = SerializedMessage + JSONserializedMessage;
//may be this is stupid but i want something really work like this

Please correct me if I got anything wrong here.

Thanks in Advance..

Jeya suriya
  • 29
  • 1
  • 5
  • [`SerializeToString` stores binary data in the string](https://developers.google.com/protocol-buffers/docs/cpptutorial?hl=en) (not ASCII/UTF-8 text). There are ways to convert `std::string` to `std::wstring`, but they don't make any sense here, as your `SerializedMessage` doesn't contain text (again, it contains the binary data of the proto message). – Cornstalks Aug 27 '15 at 13:54
  • Hi @ Cornstalks , Thank you for your reply. I have referred some links where I could not get the answers. Could you please refer me some valuable links where I can fins the solution to convert the "std::string" to "std::wstring" . Thank you so much. – Jeya suriya Aug 28 '15 at 04:11
  • [You're question is already marked as a duplicate that has the exact answer to that question](http://stackoverflow.com/questions/2573834/c-convert-string-or-char-to-wstring-or-wchar-t). However, like I've said, it's useless to you. Your `SerializedMessage` is not text. There is no meaningful conversion of it to a `std::wstring`. `letterMessage.SerializeToString()` just saves the binary data of the proto to the string. It's proto-encoded binary data, not UTF-8 encoded text. – Cornstalks Aug 28 '15 at 14:07
  • Thank you for your replay @ cornstalks. okay. Point is " concatenate the Json serialized and protobuf serialized message into a single string " --> Is this meaningful ?? – Jeya suriya Aug 28 '15 at 14:14

0 Answers0