Comment #5 on issue 249 by [email protected]: Default values are not assumed to be filled in.
http://code.google.com/p/protobuf/issues/detail?id=249

It sounds like there is still some confusion over the meaning of "set."

It is always legal to access a field from a protobuf, whether it is explicitly set or not. Using a default value with option, it is true that no information would be "set" by default, but I don't think you care: the default value provides a way of specifying what value is returned when the value is not explicitly set.
e.g.:

message MyProto {
  optional string foo = 1 [ default = "some value" ];
}

MyProto bar;
assert(!bar.has_foo());
assert(bar.foo() == "some value");

The above assertions succeed. The value foo is not explicitly set but accessing the field returns the default. This sounds like what you want.

If you change the field to required, then that means when serializing and parsing messages, that field must be explicitly set. It sounds like the data validation you have depends on the use-case - you should really do such validation at the application level, rather than using the required mechanism. In fact, many people (myself included) advocate not using required at all.

If you want to continue this discussion let's do so on the groups mailing list: [email protected]

--
You received this message because you are subscribed to the Google Groups "Protocol 
Buffers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to