ProtoBuf 3
ProtoBuf
如今Google官方的ProtoBuf已经出了ProtoBuf的C-sharp版本,使用proto3语言标准,使用库文件需要.Net4.x,需要在Unity的PlayerSettings中将.Net旧版本切换至4.xProtobuf与BinaryFormatter比较
可以参阅这篇目的
提升序列化反序列化速度,减小二进制文件大小提高传输效率,协议文件更具有可读性。定义协议格式
首先是包体说明,防止在不同项目中命名冲突syntax = “proto3”;
package tutorial;如果没有用以下官方例子中的方式将csharp_namespace指定一个命名空间的话,将会默认使用package来进行匹配。
option csharp_namespace = “Google.Protobuf.Examples.AddressBook”;
接着是定义message,可以使用一些基本类型作为字段类型,甚至还能在其它的message中使用已经定义的message类型作为字段类型。
message Person {
string name = 1;
int32 id = 2; // Unique ID number for this person.
string email = 3;
enum PhoneType {
MOBILE