Example #1
0
 static int QPYX_PeekUInt16_YXQP(IntPtr L_YXQP)
 {
     try
     {
         int QPYX_count_YXQP = LuaDLL.lua_gettop(L_YXQP);
         if (QPYX_count_YXQP == 2)
         {
             DNet.Buffer QPYX_obj_YXQP  = (DNet.Buffer)ToLua.CheckObject <DNet.Buffer>(L_YXQP, 1);
             int         QPYX_arg0_YXQP = (int)LuaDLL.luaL_checknumber(L_YXQP, 2);
             ushort      QPYX_o_YXQP    = QPYX_obj_YXQP.PeekUInt16(QPYX_arg0_YXQP);
             LuaDLL.lua_pushnumber(L_YXQP, QPYX_o_YXQP);
             return(1);
         }
         else if (QPYX_count_YXQP == 3)
         {
             DNet.Buffer QPYX_obj_YXQP  = (DNet.Buffer)ToLua.CheckObject <DNet.Buffer>(L_YXQP, 1);
             int         QPYX_arg0_YXQP = (int)LuaDLL.luaL_checknumber(L_YXQP, 2);
             bool        QPYX_arg1_YXQP = LuaDLL.luaL_checkboolean(L_YXQP, 3);
             ushort      QPYX_o_YXQP    = QPYX_obj_YXQP.PeekUInt16(QPYX_arg0_YXQP, QPYX_arg1_YXQP);
             LuaDLL.lua_pushnumber(L_YXQP, QPYX_o_YXQP);
             return(1);
         }
         else
         {
             return(LuaDLL.luaL_throw(L_YXQP, "invalid arguments to method: DNet.Buffer.PeekUInt16"));
         }
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
Example #2
0
    static int PeekUInt16(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                DNet.Buffer obj  = (DNet.Buffer)ToLua.CheckObject <DNet.Buffer>(L, 1);
                int         arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                ushort      o    = obj.PeekUInt16(arg0);
                LuaDLL.lua_pushnumber(L, o);
                return(1);
            }
            else if (count == 3)
            {
                DNet.Buffer obj  = (DNet.Buffer)ToLua.CheckObject <DNet.Buffer>(L, 1);
                int         arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                bool        arg1 = LuaDLL.luaL_checkboolean(L, 3);
                ushort      o    = obj.PeekUInt16(arg0, arg1);
                LuaDLL.lua_pushnumber(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: DNet.Buffer.PeekUInt16"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #3
0
        private void ProcessBuffer(byte[] data)
        {
            if (mReceiveBuffer == null)
            {
                mReceiveBuffer = Buffer.Create(msgProtocolType);
                mReceiveBuffer.BeginWriting(false).Write(data);
            }
            else
            {
                mReceiveBuffer.BeginWriting(true).Write(data);      //如果之前的包没处理完全,则继续添加
            }
            //首先判断是否收满了一个完整包的最小长度
            for (int available = mReceiveBuffer.size - mOffset; available >= packetLenMin;)
            {
                //计算一个完整包的长度,包括包头和包尾
                if (mExpected == 0)
                {
                    if (msgProtocolType == 1 || msgProtocolType == 2)
                    {
                        mExpected = (int)mReceiveBuffer.PeekUInt32(mOffset + packetHeadLenOffest) + packetLenMin;    //收到的包第3-7个字节为包的长度
                        // Debug.LogWarning(string.Format("cmd: {3}  -- mExpected大小:{0}  --  available大小:{1} -- packetLenMin{2}", mExpected, available,  packetLenMin, mReceiveBuffer.PeekUInt32(0)));
                    }
                    else
                    {
                        mExpected = mReceiveBuffer.PeekUInt16(mOffset + packetHeadLenOffest, true) + packetLenMin;               //收到的包第0-1个字节为整个包包的长度
                        // Debug.LogFormat("bytes={0} expected={1}", bytes,  mExpected);
                    }
                }

                //正好是一个完整包
                if (available == mExpected)
                {
                    if (mOffset > 0)    //如果是多个包的最后一个包
                    {
                        mReceiveBuffer.BeginWriting(false).Write(mReceiveBuffer.buffer, mOffset, (int)mExpected);
                    }
                    EnqueuePacker(mReceiveBuffer);
                    mReceiveBuffer = null;
                    mExpected      = 0;
                    mOffset        = 0;
                    break;
                }
                if (available > mExpected)     //收到大于一个包
                {
                    int    realSize = mExpected;
                    Buffer temp     = Buffer.Create(msgProtocolType);

                    temp.BeginWriting(false).Write(mReceiveBuffer.buffer, mOffset, realSize);
                    EnqueuePacker(temp);

                    temp       = null;
                    available -= mExpected;
                    mOffset   += realSize;
                    mExpected  = 0;
                }
                else
                {
                    break;
                }
            }
        }