On Thu, Feb 16, 2017 at 2:47 PM, Ben Hsu <[email protected]> wrote:
> Hello.
>
> Please check my understanding of protobuf serialization and defaults.
>
> I understand that if the value of a protobuf field is the same as the
> default, then its not serialized.
>
That's is proto3 semantics. Since you are using 2.5.0, you are using proto2
syntax and that means fields have presence info attached with it. That is:
setting a field to the default value is different from the field being
untouched/unset.
>
> Does that mean that if I have a field like
>
> string foo = 1 [default=""];
>
> And I explicitly set it to empty string:
>
> bar.setFoo("");
>
Use bar.clearFoo() instead.
>
> or
>
> bar.setFoo(fooString); // fooString=""
>
> then I get the serialization savings?
>
> Or do I need to do something like:
>
> if ( foo != "" ) {
> bar.setFoo(foo);
> }
>
> This is libprotobuf version 2.50, using Java
>
> --
> 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.