It's also worth noting that doing :

x_original.IsInitialized() 

will return true, even though it cannot be deserialized.

On Wednesday, June 18, 2014 12:26:10 PM UTC-4, Justin wrote:
>
> My team and I noticed a potential bug in the serialization process, that 
> seems unintended.
>
> If I defined a message structure as follows:
>
> message X {
>    required Y y = 1;
> }
>
> message Y {
>    repeated Things things = 1;
>    repeated Stuff stuff = 2;
> }
>
> message Things {
>    required string name = 1;
> }
>
> message Stuff {
>    required string name = 1;
> }
>
>
> When I create an object of type X, serialize and deserialize it, using the 
> following code (for example):
>
> X x_original;
> std::string x_content;
> x_original.SerializeToString(&x_content);
>
> X x_new;
> x_new.ParseFromString(x_content);
>
>
> The ParseFromString call will throw an error :
>
>    [libprotobuf ERROR google/protobuf/message_lite.cc:123] Can't parse 
> message of type "testDomain.X" because it is missing required fields: y
>
>
> Our intended use case for this is, in our example, letting another 
> application know that there are no Things and no Stuff available, so I 
> believe this should work as written.
>
> if I, however, change the code to :
>
> X x_original;
> Y y;
> x_original.mutable_y()->CopyFrom(y);
> std::string x_content;
> x_original.SerializeToString(&x_content);
>
> X x_new;
> x_new.ParseFromString(x_content);
>
>
> It works fine, as I believe would set_allocated_y() if I used a *y. 
>
> Is this an intended 'feature' and should I be doing something different?
>
> Thanks,
> Justin
>

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to