Hi Paul.

Apologies for the message definition.  It was a typo and should have
read like so...

message StringTestProto {
  required string property = 1;

The C++ side is setting things correctly.  My understanding is that
default values are not sent over the wire.  When building a received
message from a byte[ ] a check is done to see if required fields have
been set.  Any required field that was not sent due to having a
default value on the other side is not marked as being set and the
exception gets thrown.

Any ideas or further input appreciated.

On Oct 25, 5:53 pm, Paul <mjpabl...@gmail.com> wrote:
> I've gotten this message for reasons other than the field not being
> set.  make sure that you have the number of bytes on the delimiters
> set correctly on the C++ side.  also, maybe stringProperty should be
> string Property (two words).
> On Oct 22, 9:12 am, locky <true.n...@gmail.com> wrote:
> > I have a question regarding required string properties and default
> > values.
> > 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