コード例 #1
0
 protected override void RecycleChildren(ntf_battle_frame_data netData)
 {
     for (int i = 0; i < netData.slot_list.Count; i++)
     {
         ProtoFactory.Recycle(netData.slot_list[i]);
     }
 }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        msg.requestSeq++;
        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]++;
        msg.msgProto = data;

        int realLen = SerializeMessage(msg, sendStreamBuffer, 0);

        if (realLen == 0)
        {
            Debug.LogError("realLen == 0");
        }
        sendStreamBuffer.CopyTo(mReceiveStreamBuffer.GetBuffer(), 0, 0, realLen);
        int msgLen = 0;

        DeserializeMessage(mReceiveStreamBuffer, 0, realLen, ref msgLen, ref msg);
        if (msgLen == 0)
        {
            Debug.LogError("msgLen == 0");
        }
        Debug.Log("msg.requestSeq = " + msg.requestSeq);
        PrintData(msg.msgProto as ntf_battle_frame_data);
        ProtoFactory.Recycle(msg.msgProto as ntf_battle_frame_data);
    }
コード例 #3
0
 protected override void RecycleChildren(ntf_battle_frame_data.cmd_with_frame netData)
 {
     if (netData.cmd != null)
     {
         ProtoFactory.Recycle(netData.cmd);
     }
 }
コード例 #4
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]++;
    }
コード例 #5
0
ファイル: CSAndLuaPBTest.cs プロジェクト: xiangry/MyFramework
    private void TestLuaEncodeAndCSDecode(byte[] luaEncodeBytes)
    {
#if !FOR_GC_TEST
        // 打印字节流
        Debug.Log("CS receive from Lua =================>>>" + luaEncodeBytes.Length + " bytes : ");
        var sb = new StringBuilder();
        for (int i = 0; i < luaEncodeBytes.Length; i++)
        {
            sb.AppendFormat("{0}\t", luaEncodeBytes[i]);
        }
        Logger.Log(sb.ToString());
#endif

        // 解析协议
        msRecive.ResetStream();
        msRecive.CopyFrom(luaEncodeBytes, 0, 0, luaEncodeBytes.Length);
        ntf_battle_frame_data dataTmp = ProtoBufSerializer.Deserialize(msRecive.memStream, typeof(ntf_battle_frame_data), (int)luaEncodeBytes.Length) as ntf_battle_frame_data;
#if !FOR_GC_TEST
        PrintData(dataTmp);
#endif
        ProtoFactory.Recycle(dataTmp);//*************回收,很重要
    }
コード例 #6
0
ファイル: CSAndLuaPBTest.cs プロジェクト: xiangry/MyFramework
    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);
    }