http://www.cplusplus.com/reference/string/string/string/
std::string(buf) will be initialized with null terminated string. If the
serialized data contains 0, it will be truncated in the string.
I think you should use std::string(buf, n)

On Thu, Jun 8, 2017 at 9:57 AM David Zhao <[email protected]> wrote:

> another example:
> #include "client.h"
> #include "proto/uMemcached.pb.h"
>
> int main() {
>
>     //Client client("127.0.0.1", 27777);
>     //client.run();
>
>     mcmessage::Query query;
>     query.set_type(mcmessage::Query::SET);
>     query.set_key("good");
>     query.set_value("bad");
>
>     std::string str;
>     char buf[1024] = {0};
>
>     query.SerializeToString(&str);
>     query.SerializeToArray(buf, query.ByteSize());
>
>     std::cout << "str: " << str << std::endl;
>
>     std::cout << "buf: " << buf << std::endl;
> }
>
> run it, get:
>
>> str:goodâ–’bad
>> buf:
>>
>
> the buf is not filled.
> why.....
>
> --
> 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].
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