Compiling protobufs for C# and Java -


for compilations c# files, our .proto files contain lines this:

option (google.protobuf.csharp_file_options).namespace = "com.test.foo.someclass"; 

i'd use these proto files java (i have requisite java_package option set), if compile sorts of errors. removing csharp stuff results in fine compilation java.

is there anyway can use same files compile c# , java?

using proto2, , protoc 2.5 , protobuf-java 2.5

edit: here's of java compilations errors:

com.test.foo.protobuf.csharpoptions cannot resolved type com.test.foo.protobuf.csharpoptions cannot resolved variable 

edit2: build process script runs this:

${protoc} -i=/absolute/path/to/proto --java_out=src/main/java /absolute/path/to/proto/*.proto 

edit3: here's quick example. here's directory structure:

[~/source/shared/example]$ find . . ./contact.proto ./google ./google/protobuf ./google/protobuf/descriptor.proto ./google/protobuf/csharp_options.proto 

csharp_options.proto , descriptor can found here.

here's contents of contact.proto:

package example.data.protocolbuffer;  import "google/protobuf/csharp_options.proto"; option java_package = "com.example.data.protobuf"; option java_outer_classname = "contactproto";  option (google.protobuf.csharp_file_options).namespace = "example.data.protocolbuffer.contact";  message contact {         required string name = 1;         required string address = 2;         repeated int32 rank = 3; } 

upon executing protoc script (see edit 2), creates following:

[~/source/prototest]$ find . . ./src ./src/main ./src/main/java ./src/main/java/com ./src/main/java/com/example ./src/main/java/com/example/data ./src/main/java/com/example/data/protobuf ./src/main/java/com/example/data/protobuf/contactproto.java 

currently i'm using eclipse compilation. (no maven yet). in eclipse reports following compiler errors:

google cannot resolved   contactproto.java    google cannot resolved variable contactproto.java 

here's offending code:

    ...     com.google.protobuf.extensionregistry registry = com.google.protobuf.extensionregistry.newinstance(); registry.add(google.protobuf.csharpoptions.csharpfileoptions); //compiler error               return registry;             }           };         com.google.protobuf.descriptors.filedescriptor           .internalbuildgeneratedfilefrom(descriptordata,             new com.google.protobuf.descriptors.filedescriptor[] {               google.protobuf.csharpoptions.getdescriptor(), //compiler error             }, assigner);       } 

as can see expects csharpoptions present, not.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -