Protocol Buffers實現Java 序列化和反序列化
【1】背景原理: (1):.Google Protocol Buffer 的使用和原理 (2):Protocol Buffer技術詳解(Java實例)
【2】定義數據結構:(1).proto文件 (2)保存文件PersonMsg.proto(注意文件名和裏面的message名不要一樣)
syntax = "proto2";
message Person {
// ID(必需)
required int32 id = 1;
// 姓名(必需)
required string name = 2;
// email(可選)
optional string email = 3;
// 朋友(集合)
repeated string friends = 4;
// email (集合)
repeated string emails = 5;
}
其中 說明:
syntax = "proto2"; 爲定義使用的版本號, 目前常用版本proto2/proto3
m