/// <summary> /// 构建消息数据包 /// </summary> /// <param name="protobufModel"></param> /// <param name="messageId"></param> byte[] BuildPackage(C2GMessage c2g) { byte[] b = ProtobufSerilizer.Serialize(c2g); ByteBuffer buf = ByteBuffer.Allocate(b.Length + 3); buf.WriteShort((short)(b.Length)); //TODO 对预留字节的处理 buf.WriteByte(new byte()); buf.WriteBytes(b); return(buf.GetBytes()); }
/// <summary> /// 构建消息数据包 /// </summary> /// <param name="protobufModel"></param> /// <param name="messageId"></param> byte[] BuildPackage(Message c2s) { byte[] b = ProtobufSerilizer.Serialize(c2s.message); ByteBuffer buf = ByteBuffer.Allocate(b.Length + 4 + 4); buf.WriteInt(b.Length); //buf.WriteShort((short)(b.Length)); buf.WriteInt((int)c2s.messageId); buf.WriteBytes(b); return(buf.GetBytes()); }