Exemplo n.º 1
0
    public override object DeepCopy(object data)
    {
        one_cmd fromData = data as one_cmd;

        if (fromData == null)
        {
            throw new System.ArgumentNullException("data");
        }

        one_cmd toData = ProtoFactory.Get <one_cmd>();

        toData.cmd_id   = fromData.cmd_id;
        toData.UID      = fromData.UID;
        toData.cmd_data = StreamBufferPool.DeepCopy(fromData.cmd_data);
        return(toData);
    }
Exemplo n.º 2
0
    void Test5()
    {
        msSend.SetLength(SENF_BUFFER_LEN);
        msSend.Seek(0, SeekOrigin.Begin);

        ntf_battle_frame_data dataTmp = ProtoFactory.Get <ntf_battle_frame_data>();

        ntf_battle_frame_data.one_slot       oneSlot      = ProtoFactory.Get <ntf_battle_frame_data.one_slot>();
        ntf_battle_frame_data.cmd_with_frame cmdWithFrame = ProtoFactory.Get <ntf_battle_frame_data.cmd_with_frame>();
        one_cmd oneCmd = ProtoFactory.Get <one_cmd>();

        cmdWithFrame.cmd = oneCmd;
        oneSlot.cmd_list.Add(cmdWithFrame);
        dataTmp.slot_list.Add(oneSlot);
        DeepCopyData(data, dataTmp);
        ProtoBufSerializer.Serialize(msSend, dataTmp);
        ProtoFactory.Recycle(dataTmp);      //*************回收,很重要

        msSend.SetLength(msSend.Position);  //长度一定要设置对
        msSend.Seek(0, SeekOrigin.Begin);   //指针一定要复位
        //msRecive.SetLength(msSend.Length);//同理,但是如果Deserialize指定长度,则不需要设置流长度
        msRecive.Seek(0, SeekOrigin.Begin); //同理

        Buffer.BlockCopy(msSend.GetBuffer(), 0, msRecive.GetBuffer(), 0, (int)msSend.Length);

        dataTmp = ProtoBufSerializer.Deserialize(msRecive, typeof(ntf_battle_frame_data), (int)msSend.Length) as ntf_battle_frame_data;

        PrintData(dataTmp);
        ProtoFactory.Recycle(dataTmp);//*************回收,很重要

        data.server_curr_frame++;
        data.server_to_slot++;
        data.server_from_slot++;
        data.time++;
        data.slot_list[0].slot++;
        data.slot_list[0].cmd_list[0].server_frame++;
        data.slot_list[0].cmd_list[0].cmd.cmd_id++;
        data.slot_list[0].cmd_list[0].cmd.UID++;
        data.slot_list[0].cmd_list[0].cmd.cmd_data[0]++;
        data.slot_list[0].cmd_list[0].cmd.cmd_data[DATA_BYTE_LENGTH - 1]++;
    }
Exemplo n.º 3
0
    private void TestCSEncodeAndLuaDeconde()
    {
#if !FOR_GC_TEST
        Logger.Log("=========================NewRound=========================");
#endif
        msSend.ResetStream();

        ntf_battle_frame_data                dataTmp      = ProtoFactory.Get <ntf_battle_frame_data>();
        ntf_battle_frame_data.one_slot       oneSlot      = ProtoFactory.Get <ntf_battle_frame_data.one_slot>();
        ntf_battle_frame_data.cmd_with_frame cmdWithFrame = ProtoFactory.Get <ntf_battle_frame_data.cmd_with_frame>();
        one_cmd oneCmd = ProtoFactory.Get <one_cmd>();
        cmdWithFrame.cmd = oneCmd;
        oneSlot.cmd_list.Add(cmdWithFrame);
        dataTmp.slot_list.Add(oneSlot);
        DeepCopyData(data, dataTmp);
        ProtoBufSerializer.Serialize(msSend.memStream, dataTmp);
        ProtoFactory.Recycle(dataTmp);//*************回收,很重要

        byte[] sendBytes = StreamBufferPool.GetBuffer(msSend, 0, (int)msSend.Position());

#if !FOR_GC_TEST
        // 打印字节流和数据
        Debug.Log("CS send to Lua =================>>>" + sendBytes.Length + " bytes : ");
        var sb = new StringBuilder();
        for (int i = 0; i < sendBytes.Length; i++)
        {
            sb.AppendFormat("{0}\t", sendBytes[i]);
        }
        Logger.Log(sb.ToString());
        PrintData(data);
#endif

        ForCSCallLua(sendBytes);

        IncreaseData();
        StreamBufferPool.RecycleBuffer(sendBytes);
    }