Just to echo this, I think that having empty fields be distinguishables from ones set to the default value is an immensely useful feature, irrespective of whether the field is a primitive type or not. I know I've used it lots of times.
On Wed, Jul 1, 2015 at 4:28 PM, John C. <[email protected]> wrote: > My understanding is that if a primitive field is empty in a v3 message then > it will give 0 which is indistinguishable from a field that is actually 0. > From what I have read is this is done to enable support of a wide range of > languages, but how is this a well reasoned solution to this problem? The > response to me might be "well just explicitly include a 'has_field' boolean > to indicate the presence of a field", but I have messages with many optional > fields and adding a "has_xxx" field for each makes the message definition so > ugly that I feel overcome by waves of nausea. What initially attracted me > to protocol buffers is the ability to define messages in a single place > rather than using say JSON where the protocol can easily end up being > distributed over multiple source files. > > My solution for this big problem is an ugly hack but better than any other > ugly hack: for primitive fields code the value as (val*2) | 1. This > guarantees all present fields are non-zero so empty fields can be detected. > I think a better solution would be to, at least, have an API that I can use > to determine if a field is present or not. Since the v3 work is still in > alpha, my hope is that someone comes to their senses. > > If not for the much better Ruby performance with v3 I would stick with v2 > but the improvement is undeniable so v3 with ugly hack it is for now. > > -- > 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 http://groups.google.com/group/protobuf. > For more options, visit https://groups.google.com/d/optout. -- 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 http://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
