I am working on a project that uses Java, C# and also C++ applications. To communicate between them I am trying to use Google protocol buffer. I am using following .proto file, which was taken from examples:
package tutorial;
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phone = 4;
}
message AddressBook {
repeated Person person = 1;
}
I am referring to following tutorial: https://developers.google.com/protocol-buffers/docs/csharptutorial
Tutorials for other languages are also there.
I tried following command line arguments for each language:
Java:
C:\ProtoBuf\protoc -I=C:\trash --java_out=C:\trash C:\trash/addressbook.proto
C++:
C:\ProtoBuf\protoc -I=C:\trash --cpp_out=C:\trash C:\trash/addressbook.proto
C#:
C:\ProtoBuf\protoc -I=C:\trash --csharp_out=C:\trash C:\trash/addressbook.proto
Java and C++ compilations work properly even with some warning in case of Java. But I get following output with C# :
--csharp_out: protoc-gen-csharp: The system cannot find the file specified.
I am using this compiler: https://github.com/google/protobuf/releases/download/v2.6.1/protoc-2.6.1-win32.zip
What am I doing wrong here? do I need any other files for C# compilation?
Introducing Gen C: The YouTube Generation Gen C is a powerful new force in consumer culture. It's a term we use to describe people who care deeply about creation, curation, connection, and community. It's not an age group; it's an attitude and mindset defined by key characteristics.
Generation X, a term typically used to describe the generation of Americans born between 1965 and 1980, although some sources used slightly different ranges. It has sometimes been called the “middle child” generation, as it follows the well-known baby boomer generation and precedes the millennial generation.
You are trying to generate C# files using the old version of the protoc
protoc-2.6.1-win32.zip
C# code generator for both proto2 and proto3 was introduced only in Version 3.0.0-alpha-3
Introduced two new language implementations (Objective-C, C#) to proto3.
So, download protoc Version 3.0.0-alpha-3, install it and call:
protoc -I=$SRC_DIR --csharp_out=$DST_DIR $SRC_DIR/your.proto
Beware that started from Version 3.0.0-beta-1 C# code generator only supports generating proto3:
Proto3 semantics supported; proto2 files are prohibited for C# codegen
I know how to gen proto files in c#
I write a python script to gen proto files, gen.py
import os, subprocess, threading
def main():
with open("conf.txt") as file:
exe = os.path.join(os.getcwd(), "..\\Package\\Google.ProtocolBuffers.2.4.1.555\\tools\\ProtoGen.exe")
out = "-output_directory=%s" % (os.path.join(os.getcwd(), "..\\Common\\libs\\protos"))
def gen(proto):
subprocess.check_call([exe, os.path.join("protos", proto), out])
list = []
for proto in file.read().split(','):
t = threading.Thread(target = gen, args = (proto, ))
t.start()
list.append(t)
for t in list:
t.join()
if __name__ == '__main__':
main()
conf.txt
base.proto,test.proto,addressbook.proto
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With