Permalink
Browse files

(piqi) Add a new .protobuf-prefix property for enum

.protobuf-prefix defines a prefix that is automatically added to each enum
option's name in .proto modules converted from .piqi using "piqi to-proto"
command.

It helps to deal with the fact that Protobuf-generated enum defintions do not
form a C++ namespace meaning that enum constants are defined directly in the
outer namespace; it was announced that this problem will be fixed in
protobuf-2.5
  • Loading branch information...
1 parent ad93ce4 commit 346ec77e61a8b2ca9a8e79623a0ba04b1250a006 @alavrik committed Sep 17, 2012
Showing with 55 additions and 13 deletions.
  1. +10 −3 piqi-tools/piqi_to_proto.ml
  2. +10 −6 piqi/piqi.piqi
  3. +24 −0 piqi/piqi.protobuf.piqi
  4. +11 −4 piqicc/boot/piqi_piqi.ml
@@ -258,17 +258,24 @@ let gen_record ?name ?parent r =
in rdef
-let gen_const c =
+let gen_const prefix c =
let open O in
+ let name = ios (some_of c.protobuf_name) in
+ let prefixed_name =
+ match prefix with
+ | None -> name
+ | Some p -> ios p ^^ name
+ in
iod " " [
- ios (some_of c.protobuf_name); ios "="; gen_code c.code ^^ ios ";";
+ prefixed_name; ios "="; gen_code c.code ^^ ios ";";
]
let gen_enum e =
let open E in
let enum_name = some_of e.protobuf_name in
- let const_defs = List.map gen_const e.option in
+ let prefix = e.protobuf_prefix in
+ let const_defs = List.map (gen_const prefix) e.option in
let make_enum_def name =
iol [
ios "enum "; ios name; ios " {"; indent;
View
@@ -191,12 +191,16 @@
.name piqi-type
- .option [ .name int .protobuf-name "piqi_type_int" ]
- .option [ .name float .protobuf-name "piqi_type_float" ]
- .option [ .name bool .protobuf-name "piqi_type_bool" ]
- .option [ .name string .protobuf-name "piqi_type_string" ]
- .option [ .name binary .protobuf-name "piqi_type_binary" ]
- .option [ .name any .protobuf-name "piqi_type_any" ]
+ % prefix all options in order to prevent clash with keywords of the Protobuf
+ % target languages
+ .protobuf-prefix "piqi_type_"
+
+ .option [ .name int ]
+ .option [ .name float ]
+ .option [ .name bool ]
+ .option [ .name string ]
+ .option [ .name binary ]
+ .option [ .name any ]
]
@@ -23,6 +23,10 @@
.include [ .module piqi ]
+%
+% properties specific to .piqi to .proto conversion
+%
+
.extend [
(.typedef record field variant option enum alias list)
@@ -97,6 +101,26 @@
]
+.extend [
+ .typedef enum
+
+ .with.field [
+ % prefix each enum option's name with the specified string; it helps to
+ % deal with the fact that enum doesn't form a C++ namespace meaning that
+ % enum constants are defined directly in the outer namespace; it was
+ % announced that this problem will be fixed in protobuf-2.5
+
+ .name protobuf-prefix
+ .type string
+ .optional
+ ]
+]
+
+
+%
+% definitions and extensions related to how data is represented on the wire
+%
+
.enum [
.name protobuf-wire-type
Oops, something went wrong.

0 comments on commit 346ec77

Please sign in to comment.