作为Google出品的开源项目,其性能和效率是非常出众的,只是支持的语言不多,普及率没有thrift、JSon等广,但我相信众人拾柴火焰高,其使用率肯定会越来越高的。使用Protobuf时间不长,仅仅摘记普遍的流程方法,供大家参考,也方便自己温故。
1.protoc协议编写
package com.MyCompany; //包
message Person
{
required string name = 1;
required sint32 age = 2;
required string home = 3;
enum HOBBY
{
RUNNING = 0;
BADMINTION = 1;
PINGPONG = 3;
}
optional HOBBY hobby = 4[default = RUNNING];
}
message Company
{
repeated Person staff = 1[packed=true];
required Person boss = 2;
enum FIELD
{
IT = 0;
MECHINE = 1;
SECURITY = 2;
}
required FIELD field = 3;
required fixed32 staff_num = 4;
optional fixed32 rank = 5[default = 1];
repeated uint32 vecInt = <