Re: Zero enums

2008-10-27 Thread Kenton Varda
Added to my todo list.

On Sat, Oct 25, 2008 at 1:19 AM, Marc Gravell [EMAIL PROTECTED]wrote:


 Ah! Right. That makes more sense. Could that perhaps be added to the
 language guide Optional Fields And Default Values?

 Marc
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Re: Zero enums

2008-10-25 Thread Marc Gravell

Ah! Right. That makes more sense. Could that perhaps be added to the
language guide Optional Fields And Default Values?

Marc
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Zero enums

2008-10-24 Thread Marc Gravell

I'm writing the code-generation logic for protobuf-net, and I have got
it loading a compiled proto set (FileDescriptorSet). However, when
doing this I had a number of issues with invalid enum values (from
descriptor.proto, compiled via protoc).

In particular, OptimizeMode, CType and FieldDescriptorProto.Type.

So:
* have I doe something wrong (i.e. I shouldn't be seeing these zeros)?
or
* should protobuf-net accept zero enums even if no such enum is
defined?
or
* is the descriptor.proto lacking some zeros that should be there?

(if I add the missing zero enum values it works fine and I can happily
read and report on the FileDescriptorSet)

Thanks,

Marc
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Re: Zero enums

2008-10-24 Thread Marc Gravell

I might have found the answer... if you try to provide a different
value, the parser will treat it like an unknown field (from the
language guide). So this means that enums are essentially unchecked:
invalid values are silently ignored?

Marc
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Re: Zero enums

2008-10-24 Thread Marc Gravell

More: actually, the problem wasn't in the file - it was in the
defaults... for example:

  enum Label {
// 0 is reserved for errors
LABEL_OPTIONAL  = 1;
LABEL_REQUIRED  = 2;
LABEL_REPEATED  = 3;
// TODO(sanjay): Should we add LABEL_MAP?
  };
  ...
  optional Label label = 4

The protobuf-net code was having a hard time thinking about the
default value for label (field 4)... the natural implicit default is
zero, which doesn't exist. So: should Label have a default value? Or
what?

Marc


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Re: Zero enums

2008-10-24 Thread Kenton Varda
The reasoning for unknown enums being treated as unknown fields goes
something like this:
We cannot simply use an unknown numeric value since many languages do not
allow enum types to represent numeric values other than the set of values
explicitly defined for them.  Furthermore, even if they did, this could lead
to security problems:  people might write server code which assumes that an
enum field has one of the defined values and does something bad if it isn't.
 Such problems could easily get past code review and testing.

On the other hand, in the case of servers which simply act as a proxy,
forwarding messages elsewhere, we do not want to have to upgrade these
servers every time a new enum value is added to the proto definition.
 Instead, we would like these servers to be able to pass the message through
retaining the value they read in, valid or not.  This is exactly why unknown
fields exist in the first place, so treating it as an unknown field seems
appropriate.

On Fri, Oct 24, 2008 at 1:53 PM, Marc Gravell [EMAIL PROTECTED]wrote:


 I might have found the answer... if you try to provide a different
 value, the parser will treat it like an unknown field (from the
 language guide). So this means that enums are essentially unchecked:
 invalid values are silently ignored?

 Marc
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Re: Zero enums

2008-10-24 Thread Marc Gravell

Makes sense - it just seems a little odd that the optional enums don't
have a valid default...

Marc
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Re: Zero enums

2008-10-24 Thread Kenton Varda
Oh, the implicit default for enums is the first defined value, not zero.

On Fri, Oct 24, 2008 at 3:03 PM, Marc Gravell [EMAIL PROTECTED]wrote:


 Makes sense - it just seems a little odd that the optional enums don't
 have a valid default...

 Marc
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---