C++ compatibility

96 views
Skip to first unread message

Walter Schulze

unread,
Jun 2, 2014, 8:20:52 AM6/2/14
to gogopr...@googlegroups.com
It seems that I have made some mistakes which I can only correct by breaking a few things.

1) I had to move the descriptor.proto and
2) rename the union plugin to onlyone.

1)

The fact that gogoprotobuf extends the descriptor.proto means is has to import it.
I have placed it in code.google.com/p/gogoprotobuf/protoc-gen-gogo/descriptor which is not a problem in Go or Java from my experience.
It seems that the C++ generated code also imports the generated descriptor code located in google/protobuf/
This causes a conflict, since you can't have two descriptors.

I have moved the descriptor.proto to code.google.com/p/gogoprotobuf/protobuf/google/protobuf/descriptor.proto
I have also moved the plugin.proto to code.google.com/p/gogoprotobuf/protobuf/google/protobuf/compiler/plugin.proto
to closer reflect the folder structure in code.google.com/p/protobuf

The descriptor.proto is imported as such "google/protobuf/descriptor.proto"
gogoprotobuf rewrites this import as "code.google.com/p/gogoprotobuf/protoc-gen-gogo/descriptor" where the generated code, descriptor.pb.go, is located.

This change will require you to specify the path of the descriptor.proto using the proto_path flag.
One option for those of us which do not have a clone of code.google.com/p/protobuf is to point to the descriptor.proto in code.google.com/p/gogoprotobuf/protobuf/
If you have a clone of code.google.com/p/gogoprotobuf/protobuf/ you might not need to specify the proto_path if your sources are located correctly.

As a go user I have my sources located in a src folder under which I have a clone of gogoprotobuf at src/code.google.com/p/gogoprotobuf
I will run protoc as follows:
(cd src && protoc -I=.:code.google.com/p/gogoprotobuf/protobuf my.proto)

2)

Next the union extension causes C++ to generate code which conflicts with the union keyword.
I have changed the union keyword to onlyone, since a union can only have one value and their can only be one union.
There can only be one ;)
This will require users of the union extension to edit their proto files.

Reply all
Reply to author
Forward
0 new messages