protobuf 标签DataFormat =DataFormat.FixedSize解决连续int字段无法解析

protobuf在序列化int的时候会省去部分字节,所以在连续的int字段序列化时候会导致解析的时候不正常。

这里只需要在序列化的时候加上标签,固定字节组大小即可

 

using ProtoBuf;

// 加入房间 C_S_JOIN_GAME
[ProtoContract]
public class C_S_JoinGame
{
[ProtoMember(1,DataFormat =DataFormat.FixedSize)]
public int roomType { get; set; }// 未知(1)

[ProtoMember(2, DataFormat = DataFormat.FixedSize)]
public int roomSubType { get; set; }// 未知(1)

[ProtoMember(3, DataFormat = DataFormat.FixedSize)]
public int roomIdx { get; set; }// 房间索引号(0: 新手, 1: 精英, 2: 帝王)
}

 

参考:http://www.jianshu.com/p/e0d81a9963e9

http://blog.csdn.net/weiwangchao_/article/details/16797763

posted @ 2017-10-13 11:29  任雪松  阅读(266)  评论(0编辑  收藏  举报