环境
系统: windows7 32位
protobuf: v3
protoc下载地址: https://github.com/google/protobuf/releases
文件名称: protoc-3.1.0-win32.zip
1、解压缩protoc文件在c盘根目录;
2、“环境变量” -> “系统变量” -> 双击修改 变量”path” ,追加以下内容:
;c:\protoc-3.1.0-win32\bin
“确定”;
3、打开cmd 执行
protoc --version
命令行回复如下信息 “libprotoc 3.0.0”,至此安装完毕。
编译
-
1、d盘根目录新建文件夹 “protofile”;
2、新建文件夹”java”;
3、新建”msg.proto”,内容:
syntax = "proto3";
package proto3_proto;
message Message
{
enum Humour {
UNKNOWN = 0;
PUNS = 1;
SLAPSTICK = 2;
BILL_BAILEY = 3;
}
string name = 1;
Humour hilarity = 2;
uint32 height_in_cm = 3;
bytes data = 4;
int64 result_count = 7;
bool true_scotsman = 8;
float score = 9;
repeated uint64 key = 5[packed = true];
}
message MessageArray
{
map<string, Message> msg_map = 1;
}
4、执行编译,打开cmd 命令行
>d: (enter)
>cd protofile (enter)
>protoc --java_out=./java ./msg.proto (enter)
编译完成后,protofile\java 文件夹下会找到文件。