[libprotobuf ERROR google/protobuf/message_lite.cc:118] Can't parse message of type "RegisterWatcherResponse" because it is missing required fields: rc

1,009 views
Skip to first unread message

yihao yang

unread,
Jun 16, 2017, 5:04:52 PM6/16/17
to Protocol Buffers
I updated a proto file from proto2 to proto3 as follows.
   
Previous proto2:
message RegisterWatcherResponse {
 required int32 rc
= 1;
 optional uint64 sendTime
= 2;
}


Now proto3:
message RegisterWatcherResponse {
  int32 rc
= 1;
  optional uint64 sendTime
= 2;
}

I tested compatibility by using old version client with using proto2 RegisterWatcherResponse and receiving responses from a server using proto3 RegisterWatcherResponse.
It turns out clients got failure message like follows:
[libprotobuf ERROR google/protobuf/message_lite.cc:118] Can't parse message of type "RegisterWatcherResponse" because it is missing required fields: rc
I'm sure the server side responses have rc filed.
Can anyone help me why I got this error? Is proto3 compatible with proto2 in this scenario?
What can I do to make it work?

Thanks,
Yihao

Marc Gravell

unread,
Jun 18, 2017, 3:59:51 AM6/18/17
to yihao yang, Protocol Buffers
(I'm assumig the "optional" isn't there in the real example)

You can't simply change between proto2 and proto3. In proto3 everything is optional with an implicit zero default. This is fundamentally incompatible with consumers who have a "required" expectation **unless** you happen to never send the value zero. Because whenever your value is zero, it will be omitted and the consumer will complain about a missing required field.

Options:

- update the consumers **first** so that they don't have a "required" expectation
- never send zero in that field
- don't change to proto3

Marc

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages