Mac安装ProtoBuf并编译proto文件

安装

brew install automake
brew install libtool

上面两个好像不安装也可以

brew install protobuf

查看protoc版本

protoc --version

各系统ProtoBuf:添加链接描述

编译.proto文件为Java语言

创建.proto文件

syntax = "proto2";

// 指定生成 java 类的名字
option java_outer_classname = "MyProtoBuf";

message CislcMessage{
		required string CompanyId=1;
		required string Source=2;
		required string IPCType=3;
		required string URL=4;

		repeated BaseInfoCompany BaseInfoCompany=5;
		repeated BaseInfoCompanyStat BaseInfoCompanyStat=6;
}
message BaseInfoCompany{
		required string CompanyId=1;
		required string CompanyName=2;
		required string Identifier=3;
		required int32 Address=4;
		required string BusinessScope=5;
		required string ContactAddress=6;
		required string EconomicType=7;
		required string RegCapital=8;
		required string LegalName=9;
		required string LegalID=10;
		required string LegalPhone=11;
		optional string LegalPhoto=12;
		required int32 State=13;
		required int32 Flag=14;
		required int64 UpdateTime=15;
		required bool has_state = 16;
}
message BaseInfoCompanyStat{
		required string CompanyId=1;
		required int64 VehicleNum=2;
		required int64 DriverNum=3;
		required int32 Flag=4;
		required int64 UpdateTime=5;
}

执行 protoc 命令

protoc --java_out=/Users/winstonlau -I=/Users/winstonlau  *.proto
  • --java_out: 指定输出的 Java 文件所在的目录
  • -I:指定 proto 文件所在的目录
  • *.proto:表示在-I指定的目录下查找以.proto文件结尾的文件

默认值

  • 对于字符串,默认值是空字符串
  • 对于字节,默认值为空字节
  • 对于bool,默认值为false
  • 对于数字类型,默认值为零
  • 对于枚举,默认值是第一个定义的枚举值,必须为0。

还请注意, 如果消息字段设置为默认值, 则该值将不会序列化。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值