I have a question regarding required string properties and default

Consider the following message definition.

message StringTestProto {
  required stringProperty = 1;

I have a C++/Java setup where C++ app is producing a message and a
Java app is consuming it.

If the stringProperty value is set to an empty string I get the
following exception when trying to parse the
message once I receive it in the the Java app.

com.google.protobuf.InvalidProtocolBufferException: Message missing
required fields:

The message is being read as follows:

StringTestProto proto = StringTestProto.parseFrom(data);

>From what I can see the issue is as follows:
As the stringProperty value is the same as the default (an empty
string) it is not sent over the wire.  When the generated Java code
tries to build the proto from a byte[ ] (in the buildFrom method), a
check is done to see if the proto is initialised, this check sees if
the required fields have been set.  As the stringProperty was never
sent, the proto does not think it has been set (as it never was) and
therefore the exception is thrown.

So, how are you supposed to decode a byte[] that contains required
properties, that may have default values?

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 
For more options, visit this group at 

Reply via email to