static int ReadBytes(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                GameFramework.ByteBuffer obj = (GameFramework.ByteBuffer)ToLua.CheckObject <GameFramework.ByteBuffer>(L, 1);
                byte[] o = obj.ReadBytes();
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 2)
            {
                GameFramework.ByteBuffer obj = (GameFramework.ByteBuffer)ToLua.CheckObject <GameFramework.ByteBuffer>(L, 1);
                int    arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                byte[] o    = obj.ReadBytes(arg0);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: GameFramework.ByteBuffer.ReadBytes"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
        /// <summary>
        /// 发送缓冲数据
        /// </summary>
        public void ReSendCachedData()
        {
            if (sendedData.ReadableLen() > 0)
            {
                while (sendedData.ReadableLen() > 0)
                {
                    int readLen = int.MaxValue;

                    if (sendedData.ReadableLen() < int.MaxValue)
                    {
                        readLen = (int)sendedData.ReadableLen();
                    }

                    DoSend(sendedData.ReadBytes(readLen));
                }
            }
        }
Exemple #3
0
        public byte[] Set(ByteBuffer _bb)
        {
            _bb = new ByteBuffer(_bb.ToBytes());

            byte[] _msgid  = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(_bb.ReadInt()));
            byte[] _body   = _bb.ReadBytes();
            byte[] _length = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(_body.Length));
            byte[] _array  = new byte[_body.Length + totalHead];

            Array.Copy(_msgid, 0, _array, 0, _msgid.Length);
            Array.Copy(_length, 0, _array, 4, _length.Length);
            Array.Copy(_body, 0, _array, 8, _body.Length);

            return(_array);
        }