Exemplo n.º 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]);
     }
 }
Exemplo n.º 2
0
 protected override void RecycleChildren(ntf_battle_frame_data.cmd_with_frame netData)
 {
     if (netData.cmd != null)
     {
         ProtoFactory.Recycle(netData.cmd);
     }
 }
Exemplo n.º 3
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);
    }
Exemplo n.º 4
0
 void AddProtoPool()
 {
     // 自定义缓存池以避免ProtoBuf创建实例
     ProtoFactory.AddProtoPool(typeof(ntf_battle_frame_data), new NtfBattleFrameDataPool());
     ProtoFactory.AddProtoPool(typeof(ntf_battle_frame_data.one_slot), new OneSlotPool());
     ProtoFactory.AddProtoPool(typeof(ntf_battle_frame_data.cmd_with_frame), new CmdWithFramePool());
     ProtoFactory.AddProtoPool(typeof(one_cmd), new OneCmdPool());
 }
Exemplo n.º 5
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.º 6
0
 /// <summary>
 /// Converts this object to the transaction as defined by the integration
 /// API.
 /// </summary>
 /// <returns>transaction</returns>
 public Transaction ToTransaction()
 {
     return(new Transaction
     {
         Id = Id,
         TokenTransferId = ReferenceId,
         Type = Type,
         Status = ProtoFactory.ToTransactionStatus(status),
         Description = Description,
         Amount = new Proto.Common.MoneyProtos.Money
         {
             Value = Amount.ToString(),
             Currency = Currency
         },
         CreatedAtMs = (long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds,
     });
 }
Exemplo n.º 7
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.º 8
0
    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);//*************回收,很重要
    }
Exemplo n.º 9
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);
    }
Exemplo n.º 10
0
 void ClearProtoPool()
 {
     ProtoFactory.ClearProtoPool();
 }