On Wednesday, May 18, 2016 at 11:32:03 AM UTC-7, Feng Xiao wrote:
>
>
>
> On Tue, May 17, 2016 at 7:53 PM, Teddy Zhang <[email protected] 
> <javascript:>> wrote:
>
>> I'm really not happy to see that proto3 removed the ability in generate 
>> code for check whether a field exits or not.
>>
>> For a message like this:
>> message Test1 {
>>   required int32 a = 1;
>> }
>> If field a is present, the encoded message will have field with id 1 and 
>> its value. If the field is not set, the encoded message will not have field 
>> id 1.
>> In proto2 generated code, it provides a has method to check whether the 
>> field exists or not.
>> In proto3, this is no such thing. During deserialization, if the field is 
>> not exists, default value is set. So you can't tell whether the field does 
>> not exist or have a default value. That doesn't match the underline 
>> encoding anymore.
>>
>> This is a breaking change and will portentially impact a lot of people. 
>> Basically we're losing nullable support.
>> For our project, we heavily depends on that. There are workarounds (add 
>> a Boolean field) but it is ugly. I think that will stop us from moving from 
>> proto2 to proto3 (may need find alternatives).
>>
> There are two workarounds to get back the field presence info in proto3.
> 1. Use a wrapper message, such as google.protobuf.Int32Value 
> <https://github.com/google/protobuf/blob/master/src/google/protobuf/wrappers.proto#L84>.
>  
> In proto3, message fields still have has-bits.
>
Wrapper field consumes more space. Also, the wire format is not compatible 
when move from proto2 to proto3 (given the schema needs to change).
 

> 2. Use an oneof. For example:
> message Test1 {
>   oneof a_oneof {
>     int32 a = 1;
>   }
> }
> then you can check test.getAOneofCase().
>
Same issue as above.  

>
>
>
>> Can we add the functionality back?
>>
> It's very unlikely to happen as proto3 features are already finalized and 
> implemented in many languages.
>
Is it possible to add a option on message to control this?
I know proto3 is probably in last beta and try to avoid big changes. 
However, remove support for this creates a lot of pain in a big system 
which already leverage this feature, and may move many people away. 

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to