more protoc troubles with variants and enums

12 views
Skip to first unread message

bart van deenen

unread,
Mar 26, 2013, 5:41:36 AM3/26/13
to pi...@googlegroups.com
Hi Anton, all.

I'm trying to convert our piqi files to proto for use with a Python interface and am running into troubles with name collissions. I've narrowed it down to a simple testcase. Is there anything I can do to make this work without rewriting our piqi files, or should I forget about the protobuf conversion for now?

Thanks

Bart

L087:~/test$ cat enum.piqi
.enum [
    .name type
    .option [.name bart]
]
L087:~/test$ cat variant.piqi
.import [ .module enum ]
.variant [
    .name rsrc
    .option [ .type bart ]
]
.record [ .name bart
    .field [ .type int]
]
L087:~/test$ piqi to-proto enum.piqi
L087:~/test$ piqi to-proto variant.piqi
L087:~/test$ cat enum.piqi.proto
enum type {
    bart = 1;
}
L087:~/test$ cat variant.piqi.proto
import "enum.piqi.proto" ;
message rsrc {
    optional bart bart = 1;
}
message bart {
    required sint32 int = 1;
}
L087:~/test$ protoc enum.piqi.proto --python_out=.
L087:~/test$ protoc variant.piqi.proto --python_out=.
variant.piqi.proto:7:9: "bart" is already defined in file "enum.piqi.proto".                                             
variant.piqi.proto:4:14: "bart" is not a type.

Anton Lavrik

unread,
Mar 27, 2013, 1:19:56 AM3/27/13
to pi...@googlegroups.com
Bart,

To prevent name collisions in generated .proto files, you can put them
into different namespaces.

For instance, adding

.protobuf-package "enum"

to your enum module, this will translate to

package enum;

in the generated .proto file

Protobuf packages work very similar to C++ namespaces.

(in piqi version < 0.6.0 this property was named "proto-package"; it
is still supported under this name in 0.6.0+ but you will get a
deprecation warning)


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