On Wed, Jul 14, 2010 at 1:47 PM, mark.t.macdon...@googlemail.com
mark.t.macdon...@googlemail.com wrote:
I am new and want to understand the purpose/usage of default values in
the .proto file. E.g:
test
{
optional string a 1 [default =test];
}
When I create a message object and read the field value, the default
will be displayed:
test thing;
coutthing.a();
But when I serialise, write to a file, and inspect the binary message,
the default is absent:
string temp;
thing.SerializeToString(temp);
ofstream file(wire_message, std::ios::out | std::ios::binary);
filetemp;
file.close();
If the default values aren't serialised, what is their purpose?
Protocol buffers don't have a concept of null: the getters will always
return some kind of value. Default values allow you to control what's
returned when a field isn't explicitly set. If you don't specify a default
value you get the system default. In your case thing.a() would have
returned an empty string instead of test.
What's the rationale for not serialising them?
They aren't serialized as an optimization: since the recipient will use the
default value if a field is not explicitly set, it's unnecessary to send the
default value over the wire.
Thanks!
--
You received this message because you are subscribed to the Google Groups
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to
protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@googlegroups.com
.
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.
--
You received this message because you are subscribed to the Google Groups
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.