Status: New
Owner: liuj...@google.com
Labels: Type-Defect Priority-Medium

New issue 312 by big4...@gmail.com: Required field with default value serializes if not set
http://code.google.com/p/protobuf/issues/detail?id=312

What steps will reproduce the problem?
1. Create a simple proto file containing a required field with a default value (see test.proto)

2. Make a testprogram in which the required field is not explicitly set, then try to serialize the message (see test.cc)

3. Compile & Run

What is the expected output? What do you see instead?
I would expect the serialization to fail since IsInitialized() is false and According to the documentation @ http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.message.html#Message.SerializeToOstream.details "All required fields must be set"

With test.cc however, it sais (correctly) that has_i() is false, and the message is thus not initialized. The serialization to both Ostream and String succeed however. Finally parsing from the generated(empty) string fails as expected because there is no "i".

What version of the product are you using? On what operating system?
2.4.1 @ Ubuntu 10.04
protoc --version --> libprotoc 2.4.1
uname -a --> Linux UbuntuSan 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:46 UTC 2011 x86_64 GNU/Linux



Attachments:
        test.proto  51 bytes
        test.cc  611 bytes

--
You received this message because you are subscribed to the Google Groups "Protocol 
Buffers" group.
To post to this group, send email to protobuf@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.

Reply via email to