alopecoid
unread,Aug 20, 2010, 2:12:30 PM8/20/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Protocol Buffers
Hi,
This post is about the fact that protobuf enum values use C++ scoping
rules, meaning that, unlike in Java, enum values are siblings of their
type, not children of it.
Say I have the following contrived message:
message MyMessage {
enum Foo {
FIRST = 0;
SECOND = 1;
BOTH = 2;
}
required Foo foo = 1;
enum Bar {
FIRST = 0;
SECOND = 1;
BOTH = 2;
}
required Bar bar = 2;
}
This wouldn't compile because the protobuf compiler recognizes the
fact that for C++, the generated enum values for Foo and Bar would
conflict with each other.
However, for Java, this wouldn't be a problem. I would like to propose
that instead of "punishing" the generated Java code because of C++'s
strange enum behavior (by forcing developers to rename their enum
values even though they don't collide), that instead, the generated C+
+ enum declarations are wrapped in their own nested namespaces? For
example, something like:
namespace Foo {
enum Enum {
FIRST = 0;
SECOND = 1;
BOTH = 2;
}
}
namespace Bar {
enum Enum {
FIRST = 0;
SECOND = 1;
BOTH = 2;
}
}
At this point, the enum values would be accessed like Foo::FIRST,
Bar::FIRST, etc, which would eliminate the enum value collision
problem altogether, and at the same time make them appear to behave
more like Java's enum scoping rules (which arguably make more sense).
Thoughts?
Thank you.