Пример #1
0
    public void ChangeMsgData <V>(V tmp, ushort msgId) where V : IExtensible
    {
        byte[] tmpByte = IProtoTools.Serialize(tmp);
        buffer = new byte[tmpByte.Length + 6];
        //怎么样组成发送byte[]
        //长度
        byte[] dataLength = BitConverter.GetBytes(tmpByte.Length);

        Buffer.BlockCopy(dataLength, 0, buffer, 0, 4);
        byte[] eventId = BitConverter.GetBytes(this.msgId);
        Buffer.BlockCopy(eventId, 0, buffer, 4, 2);
        Buffer.BlockCopy(tmpByte, 0, buffer, 6, tmpByte.Length);
    }
Пример #2
0
 public void ChangeMsgData <V>(V temp) where V : IExtensible
 {
     byte[] tempByte = IProtoTools.Serialize(temp);
     buffer = new byte[tempByte.Length + 6];
     //添加长度
     byte[] dataLength = BitConverter.GetBytes(tempByte.Length);
     Buffer.BlockCopy(dataLength, 0, buffer, 0, 4);
     //添加命令
     //byte[] eventId = BitConverter.GetBytes(msgId);
     //Buffer.BlockCopy(eventId, 0, buffer, 4, 2);
     //添加data
     Buffer.BlockCopy(tempByte, 0, buffer, 6, tempByte.Length);
 }
Пример #3
0
    /// <summary>
    /// 只要外界传递msgid,PBClass
    /// </summary>
    /// <param name="tmp"></param>
    /// <param name="msgid"></param>
    public TCPNetMsgs(T tmp, ushort msgid)
    {
        this.msgId = msgId;
        byte[] tmpByte = IProtoTools.Serialize(tmp);
        buffer = new byte[tmpByte.Length + 6];
        //怎么样组成发送byte[]
        //长度
        byte[] dataLength = BitConverter.GetBytes(tmpByte.Length);

        Buffer.BlockCopy(dataLength, 0, buffer, 0, 4);
        byte[] eventId = BitConverter.GetBytes(msgId);
        Buffer.BlockCopy(eventId, 0, buffer, 4, 2);
        Buffer.BlockCopy(tmpByte, 0, buffer, 6, tmpByte.Length);
    }