码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-10-13 12:48:51      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:prot   set   taf   部分   参考   details   无法解析   public   ber   

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

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

标签:prot   set   taf   部分   参考   details   无法解析   public   ber   

原文地址:http://www.cnblogs.com/rxs123/p/7660276.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!