Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
    }
Ejemplo n.º 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);
    }
Ejemplo n.º 4
0
 /// <summary>
 /// 从Socket接受过来的数据转化成制定类
 /// </summary>
 /// <typeparam name="U"></typeparam>
 /// <returns></returns>
 public U GetPBClass <U>() where U : IExtensible
 {
     byte[] tempType = new byte[this.buffer.Length - 6];
     Buffer.BlockCopy(buffer, 6, tempType, 0, buffer.Length - 6);
     return(IProtoTools.Deserialize <U>(tempType));
 }