actually, this is also the part that confuses me some: suppose I serialize 
it to string. string.data() will return me a c-string according to c++ 
reference (I read it somewhere that since c++11, string.c_str() and 
string.data() both will return null-terminated string). Even 
protocolbuf serialized array can contain NULL, then it doesn't quite make 
sense to me yet - does string do something different behind the scene to 
make sure byte array now null-terminated, without breaking protocolbuf? 
does my line of thought make sense at all?


On Tuesday, September 18, 2018 at 4:20:51 PM UTC-4, Adam Cozzette wrote:
>
> I don't have any experience with MPI, but I would recommend using 
> SerializeToString() instead of SerializeToArray(). SerializeToString() is 
> simpler and easier because you don't have to worry about creating an array 
> of the correct size. Once you have serialized to a std::string, you can 
> just call data() and size() on that to get access to the backing array and 
> size. Note that the serialized data might contain null characters within it.
>
> On Tue, Sep 18, 2018 at 1:10 PM Oliver Wang <[email protected] 
> <javascript:>> wrote:
>
>>
>> mainly, I need to pass serialized array to MPI to transfer - MPI needs 
>> type information and size information, MPI_CHAR will treat the buffer as 
>> char*, MPI_BYTE will treat the buffer as byte stream. I am a bit fuzzy on 
>> which type I should use?  Also, if it is a c-string, maybe I don't have to 
>> pass "size" information along with it. Given your earlier reply, this is 
>> not the case.
>>
>> Thanks
>> Oliver
>>
>>
>>
>>
>> On Monday, September 17, 2018 at 4:13:44 PM UTC-4, Adam Cozzette wrote:
>>>
>>> That method will serialize the message into the provided array in the 
>>> data argument. It will not really generate a C-style string, because 
>>> the output will not be delimited by a null character. What are you trying 
>>> to do exactly?
>>>
>>> On Mon, Sep 17, 2018 at 12:18 PM Oliver Wang <[email protected]> wrote:
>>>
>>>> hi,
>>>>
>>>> It wasn't clear to me, if this following call will generate a c-string? 
>>>> if not, is there a way to do that?
>>>>
>>>>
>>>> https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message_lite?csw=1#MessageLite.SerializeToArray.details
>>>>
>>>> thanks
>>>>
>>>> oliver
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Protocol Buffers" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at https://groups.google.com/group/protobuf.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Protocol Buffers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/protobuf.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to