示例#1
0
    void PrintData(ntf_battle_frame_data data)
    {
        StringBuilder sb = new StringBuilder();

        sb.AppendLine("============================");
        sb.AppendFormat("data.server_curr_frame = {0}", data.server_curr_frame);
        sb.AppendLine();
        sb.AppendFormat("data.slot_list.Count = {0}", data.slot_list.Count);
        sb.AppendLine();
        if (data.slot_list.Count > 0)
        {
            ntf_battle_frame_data.one_slot oneSlot = data.slot_list[0];
            sb.AppendFormat("oneSlot[0].slot = {0}", oneSlot.slot);
            sb.AppendLine();
            sb.AppendFormat("oneSlot[0].cmd_list.Count = {0}", oneSlot.cmd_list.Count);
            sb.AppendLine();
            if (oneSlot.cmd_list.Count > 0)
            {
                ntf_battle_frame_data.cmd_with_frame cmdWithFrame = oneSlot.cmd_list[0];
                sb.AppendFormat("oneSlot[0].cmd_list[0].server_frame = {0}", cmdWithFrame.server_frame);
                sb.AppendLine();
                sb.AppendFormat("oneSlot[0].cmd_list[0].cmd.cmd_id = {0}", cmdWithFrame.cmd.cmd_id);
                sb.AppendLine();
                sb.AppendFormat("oneSlot[0].cmd_list[0].cmd.UID = {0}", cmdWithFrame.cmd.UID);
                sb.AppendLine();
                sb.AppendFormat("oneSlot[0].cmd_list[0].cmd.cmd_data.Length = {0}", cmdWithFrame.cmd.cmd_data.Length);
                sb.AppendLine();
                sb.AppendFormat("oneSlot[0].cmd_list[0].cmd.cmd_data[0] = {0}", cmdWithFrame.cmd.cmd_data[0]);
                sb.AppendLine();
                sb.AppendFormat("oneSlot[0].cmd_list[0].cmd.cmd_data[Length - 1] = {0}", cmdWithFrame.cmd.cmd_data[DATA_BYTE_LENGTH - 1]);
                sb.AppendLine();
            }
        }
        Debug.Log(sb.ToString());
    }
示例#2
0
    void InitData(ntf_battle_frame_data data)
    {
        ntf_battle_frame_data.one_slot       oneSlot;
        ntf_battle_frame_data.cmd_with_frame cmdWithFrame;
        one_cmd oneCmd;

        oneCmd                    = new one_cmd();
        oneCmd.UID                = 1;
        oneCmd.cmd_id             = 1;
        oneCmd.cmd_data           = new byte[DATA_BYTE_LENGTH];
        cmdWithFrame              = new ntf_battle_frame_data.cmd_with_frame();
        cmdWithFrame.server_frame = 1;
        cmdWithFrame.cmd          = oneCmd;
        oneSlot                   = new ntf_battle_frame_data.one_slot();
        oneSlot.slot              = 1;
        oneSlot.cmd_list.Add(cmdWithFrame);
        data.server_curr_frame = 1;
        data.slot_list.Add(oneSlot);
    }
示例#3
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]++;
    }
示例#4
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);
    }