protoc requires globally unique enum values

1,545 views
Skip to first unread message

bart van deenen

unread,
Mar 26, 2013, 5:17:44 AM3/26/13
to pi...@googlegroups.com
Hi Anton

I've run into an issue that I'd like you to comment on.
I have one piqi file with two different enums in it, that both have an option 'erlang'. Using piqi to-proto it generates a .proto file without complaints, but when I then run protoc on the file, protoc gives me an error:


L087:~/REBAR_DEPS/rmp/src$ protoc --python_out=. types.piqi.proto
types.piqi.proto:72:5: "erlang" is already defined.
types.piqi.proto:72:5: Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it.  Therefore, "erlang" must be unique within the global scope, not just within "encoding".

The relevant bit of the types.piqi.proto file is:
 62 enum transport {
 63     raw = 1;
 64     http = 2;
 65     erlang = 3;
 66 }
 67
 68 enum encoding {
 69     json = 1;
 70     xml = 2;
 71     pb = 3;
 72     erlang = 4;
 73 }

Is there anything we can do about this apart from renaming our enum?

Thanks

Bart


P.S. info:
L087:~/REBAR_DEPS/rmp/src$ protoc --version
libprotoc 2.4.1    
                                                                                          
piqi version
0.5.7-dev

Anton Lavrik

unread,
Mar 27, 2013, 1:08:52 AM3/27/13
to pi...@googlegroups.com
Hi Bart,

There are two standard solutions for this (quite common) problem.

1) Define .protobuf-name property inside your option(s). For example:

$ cat t.piqi
.enum [
.name e
.option [
.name o
.protobuf-name "e_o"
]
]

$ cat t.piqi.proto
enum e {
e_o = 1;
}


2. Define .protobuf-prefix property to add prefixes to all your enum
options at once -- this shorthand is supported since v0.6.0. For
example:

$ cat t.piqi
.enum [
.name e
.protobuf-prefix "e_"
.option [
.name o
]
]

$ cat t.piqi.proto
enum e {
e_o = 1;
}


Anton
> --
> You received this message because you are subscribed to the Google Groups
> "piqi" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to piqi+uns...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages