internal static RecvData CreateData(PkgPoolManager mgr, byte[] src, int len)
        {
            var pkg = mgr.QueryRecvData();

            pkg.Init(mgr, src, len);
            return(pkg);
        }
 private void Init(PkgPoolManager mgr, byte[] src, int len)
 {
     if (len >= UInt16.MaxValue)
     {
         PkgData = new byte[len];
     }
     else
     {
         PkgMgr  = mgr;
         PkgData = mgr.AllocPkg((UInt16)len);
     }
     Length   = len;
     RecvTime = Support.Time.GetTickCount();
     unsafe
     {
         //Buffer.BlockCopy(src, 0, PkgData, 0, (int)len);
         fixed(byte *ps = &src[0])
         fixed(byte *dest = &PkgData[0])
         {
             CoreSDK.SDK_Memory_Copy(dest, ps, (UInt32)len);
         }
     }
 }
        public unsafe bool ParsePackage(byte *pData, UInt32 length, FOnPacketOK onPacket, PkgPoolManager parameter)
        {
            lock (this)
            {
                //int whileCount = 0;
                while (true)
                {
                    //++whileCount;
                    //if (whileCount >= 2)
                    //{
                    //    Log.FileLog.WriteLine($"ParsePackage whileCount = {whileCount}");
                    //}

                    if (length == 0)
                    {
                        return(true);
                    }
                    unsafe
                    {
                        //包头还没有读出来,不知道长度
                        if (PacketSize == 0)
                        {
                            if (CurPos + length < PacketHeadSize)
                            {//加上新读取的都还没有完成包头
                                AppendData(pData, length, ref length);
                                return(true);
                            }
                            else
                            {
                                var remainHead = PacketHeadSize - CurPos;
                                pData = AppendData(pData, remainHead, ref length);
                                fixed(byte *pBuffer = &mDataBuffer[0])
                                {
                                    PacketSize = ((PkgHeader *)pBuffer)->PackageSize;
                                }
                            }
                        }

                        if (PacketSize == 0 || PacketSize >= UInt16.MaxValue)
                        {//被修改或者错误的包
                            return(false);
                        }

                        if (CurPos + length < PacketSize)
                        {//还不够
                            AppendData(pData, length, ref length);
                            return(true);
                        }
                        else
                        {
                            //if (PacketSize == 0)
                            //    return false;
                            pData = AppendData(pData, PacketSize - CurPos, ref length);
                            //int pkgLength = (int)PacketSize;

                            #region CreateFullPacket
                            var pkg = RecvData.CreateData(parameter, mDataBuffer, (int)PacketSize);
                            CurPos     = 0;
                            PacketSize = 0;
                            #endregion

                            onPacket(pkg);
                            //return ParsePackage(pData, length, onPacket, parameter);
                        }
                    }
                }
            }
        }