编程语言
首页 > 编程语言> > Protobuffer生成java类

Protobuffer生成java类

作者:互联网

protobuffer文件


package tutorial; option java_package = "com.example.tutorial"; option java_outer_classname = "AddressBookProtos"; 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; }


windows环境里下载protoc.exe
https://developers.google.com/protocol-buffers/docs/downloads


在PersonMsg.proto的文件夹内执行命令:
protoc.exe --java_out=E:\java PersonMsg.proto


如果一个proto文件太大,生成的类代码太多,一个java文件存不下,可以在proto文件里添加
option java_multiple_files = true;

这样,一个proto文件会生成多个java文件



相关链接:
https://github.com/google/protobuf/releases?after=v3.0.0-alpha-4.1
https://github.com/google/protobuf/tree/master/java


标签:文件,google,java,proto,Protobuffer,生成,message,com
来源: https://www.cnblogs.com/june0816/p/5740355.html