Beispiel #1
0
        static int UF_clearCBytesBuffer(IntPtr L)
        {
            CBytesBuffer buffer = UF_getCBytesBufferInPool(L);

            buffer.UF_clear();
            return(0);
        }
Beispiel #2
0
 private static void UF_ASSERT_BYTESBUFFER(CBytesBuffer buffer)
 {
     if (buffer == null)
     {
         throw new Exception("CBytesBuffer is Null");
     }
 }
Beispiel #3
0
        public static int UF_writeuint32(CBytesBuffer buffer, uint u32)
        {
            byte[] _tmp = BitConverter.GetBytes(u32);
#if BIG_ENDIAN
            UF_Reverse(_tmp);
                        #endif
            return(buffer.UF_write(_tmp, 4));
        }
Beispiel #4
0
        public static int UF_writeuint16(CBytesBuffer buffer, ushort u16)
        {
            byte[] _tmp = BitConverter.GetBytes(u16);
#if BIG_ENDIAN
            UF_Reverse(_tmp);
                        #endif
            return(buffer.UF_write(_tmp, 2));
        }
Beispiel #5
0
 public static int UF_writeuint8(CBytesBuffer buffer, byte u8)
 {
     if (buffer == null)
     {
         throw new Exception("writing buffer is null");
     }
     return(buffer.UF_write(u8));
 }
Beispiel #6
0
        static int UF_readstring(IntPtr L)
        {
            CBytesBuffer buffer = UF_getCBytesBufferInPool(L);
            string       str    = CBytesConvert.UF_readstring(buffer);

            LuaDLL.lua_pushstring(L, str);
            return(1);
        }
Beispiel #7
0
        static int UF_readnumber64(IntPtr L)
        {
            CBytesBuffer buffer = UF_getCBytesBufferInPool(L);
            long         number = CBytesConvert.UF_readnumber(buffer);

            LuaDLL.lua_pushstring(L, Convert.ToString(number));
            return(1);
        }
Beispiel #8
0
        static int UF_readboolean(IntPtr L)
        {
            CBytesBuffer buffer = UF_getCBytesBufferInPool(L);
            bool         val    = CBytesConvert.UF_readboolean(buffer);

            LuaDLL.lua_pushboolean(L, val);
            return(1);
        }
Beispiel #9
0
        static int UF_readnumber(IntPtr L)
        {
            CBytesBuffer buffer = UF_getCBytesBufferInPool(L);
            long         number = CBytesConvert.UF_readnumber(buffer);

            LuaDLL.lua_pushnumber(L, number);
            return(1);
        }
Beispiel #10
0
        public static long UF_readnumber(CBytesBuffer buffer)
        {
            if (buffer.UF_getSize() < 1)
            {
                return(0);
            }

            byte nNumberType;

            buffer.UF_read(out nNumberType);

            switch (nNumberType)
            {
            case BIT_8:
            {
                byte u8;
                buffer.UF_read(out u8);
                return((sbyte)u8);
            }

            case BIT_16:
            {
                byte[] u16;
                buffer.UF_read(out u16, 2);
#if BIG_ENDIAN
                UF_Reverse(u16);
                                        #endif
                return(BitConverter.ToInt16(u16, 0));
            }

            case BIT_32:
            {
                byte[] u32;
                buffer.UF_read(out u32, 4);
#if BIG_ENDIAN
                UF_Reverse(u32);
                                        #endif
                return(BitConverter.ToInt32(u32, 0));
            }

            case BIT_64:
            {
                byte[] u64;
                buffer.UF_read(out u64, 8);
#if BIG_ENDIAN
                UF_Reverse(u64);
                                        #endif
                //				return BitConverter.ToString(u64);
                return(BitConverter.ToInt64(u64, 0));
            }

            default:
            {
                //返回自己
                return((sbyte)nNumberType);
            }
            }
        }
Beispiel #11
0
        public static uint UF_readuint32(CBytesBuffer buffer)
        {
            byte[] _tmp;
            buffer.UF_read(out _tmp, 4);
#if BIG_ENDIAN
            UF_Reverse(_tmp);
                        #endif
            return(BitConverter.ToUInt32(_tmp, 0));
        }
Beispiel #12
0
        static int UF_getCBytesBufferSize(IntPtr L)
        {
            CBytesBuffer buffer = UF_getCBytesBufferInPool(L);
            int          size   = buffer.UF_getSize();

            LuaDLL.lua_pushnumber(L, size);

            return(1);
        }
Beispiel #13
0
        public static string UF_readuint64(CBytesBuffer buffer)
        {
            byte[] _tmp;
            buffer.UF_read(out _tmp, 8);
#if BIG_ENDIAN
            UF_Reverse(_tmp);
                        #endif
            UInt64 data = BitConverter.ToUInt64(_tmp, 0);
            return(Convert.ToString(data));
        }
Beispiel #14
0
        static int UF_createCBytesBuffer(IntPtr L)
        {
            //后续优化使用对象池形式,减少GC
            CBytesBuffer buffer = new CBytesBuffer();
            //			uint bufferid = PushInPool (buffer);
            uint bufferid = m_TableCBytesBuffer.UF_Add(buffer);

            LuaDLL.lua_pushnumber(L, bufferid);
            return(1);
        }
Beispiel #15
0
        public static bool UF_readboolean(CBytesBuffer buffer)
        {
            if (buffer == null)
            {
                throw new Exception("reading buffer is null");
            }
            int _val = (int)UF_readnumber(buffer);

            return(_val == 0 ? false : true);
        }
Beispiel #16
0
        public static int writeuint64(CBytesBuffer buffer, string u64)
        {
            UInt64 data = Convert.ToUInt64(u64);

            byte[] _tmp = BitConverter.GetBytes(data);
#if BIG_ENDIAN
            UF_Reverse(_tmp);
                        #endif
            return(buffer.UF_write(_tmp, 8));
        }
Beispiel #17
0
        public static byte UF_readuint8(CBytesBuffer buffer)
        {
            if (buffer == null)
            {
                throw new Exception("read buffer is null");
            }
            byte _b = 0;

            buffer.UF_read(out _b);
            return(_b);
        }
Beispiel #18
0
 static CBytesBuffer UF_getCBytesBufferInPool(IntPtr L)
 {
                 #if UNITY_EDITOR
     if (LuaDLL.lua_isnumber(L, 1) == 0)
     {
         LuaDLL.luaL_typerror(L, 1, "number");
     }
                 #endif
     uint         idx = (uint)LuaDLL.lua_tonumber(L, 1);
     CBytesBuffer ret = m_TableCBytesBuffer[idx];
     UF_ASSERT_BYTESBUFFER(ret);
     return(ret);
 }
Beispiel #19
0
        public static int UF_writenumber(CBytesBuffer buffer, ulong data)
        {
            //			if (data == 0)
            //			{
            //				byte type = BIT_0;
            //				return buffer.write(0);
            //			}
            if (data < VAL_8_L)
            {
                //奇怪的处理方式。。。。
                if (data < VAL_8_S)
                {
                    buffer.UF_write((byte)data);
                    return(1);
                }
                else
                {
                    buffer.UF_write(BIT_8);
                    buffer.UF_write((byte)data);
                    return(2);
                }
                //				return buffer.write(BitConverter.GetBytes(data), 1);
            }
            else if (data < VAL_16)
            {
                buffer.UF_write(BIT_16);
                byte[] _tmp = BitConverter.GetBytes((ushort)data);
#if BIG_ENDIAN
                UF_Reverse(_tmp);
                                #endif
                return(buffer.UF_write(_tmp, 2));
            }
            else if (data < VAL_32)
            {
                buffer.UF_write(BIT_32);
                byte[] _tmp = BitConverter.GetBytes((uint)data);
#if BIG_ENDIAN
                UF_Reverse(_tmp);
                                #endif
                return(buffer.UF_write(_tmp, 4));
            }
            else
            {
                buffer.UF_write(BIT_64);
                byte[] _tmp = BitConverter.GetBytes(data);
#if BIG_ENDIAN
                UF_Reverse(_tmp);
                                #endif
                return(buffer.UF_write(_tmp, 8));
            }
        }
Beispiel #20
0
        static int UF_writeboolean(IntPtr L)
        {
            CBytesBuffer buffer = UF_getCBytesBufferInPool(L);

            #if UNITY_EDITOR
            if (!LuaDLL.lua_isboolean(L, -1))
            {
                LuaDLL.luaL_typerror(L, -1, "boolean");
            }
            #endif
            bool val = LuaDLL.lua_toboolean(L, -1);
            CBytesConvert.UF_writeboolean(buffer, val);
            return(0);
        }
Beispiel #21
0
        static int UF_writenumber(IntPtr L)
        {
            CBytesBuffer buffer = UF_getCBytesBufferInPool(L);

                        #if UNITY_EDITOR
            if (LuaDLL.lua_isnumber(L, -1) == 0)
            {
                LuaDLL.luaL_typerror(L, -1, "number");
            }
                        #endif
            ulong number = (ulong)LuaDLL.lua_tonumber(L, -1);

            CBytesConvert.UF_writenumber(buffer, number);

            return(0);
        }
Beispiel #22
0
        static int UF_writenumber64(IntPtr L)
        {
            CBytesBuffer buffer = UF_getCBytesBufferInPool(L);

                        #if UNITY_EDITOR
            if (LuaDLL.lua_isstring(L, -1) == 0)
            {
                LuaDLL.luaL_typerror(L, -1, "string");
            }
                        #endif

            string str = LuaDLL.lua_tostring(L, -1);

            CBytesConvert.UF_writenumber(buffer, Convert.ToUInt64(str));

            return(0);
        }
Beispiel #23
0
        static int UF_readbytes(IntPtr L)
        {
            CBytesBuffer buffer = UF_getCBytesBufferInPool(L);
            long         len    = CBytesConvert.UF_readnumber(buffer);

            byte[] value = CBytesConvert.UF_readbytes(buffer, (int)len);

            if (value != null)
            {
                uint uniqueCode = m_TableBytes.UF_Add(value);
                LuaDLL.lua_pushnumber(L, (double)uniqueCode);
            }
            else
            {
                LuaDLL.lua_pushnil(L);
            }
            return(1);
        }
Beispiel #24
0
        static int UF_writebytes(IntPtr L)
        {
            CBytesBuffer buffer = UF_getCBytesBufferInPool(L);

                        #if UNITY_EDITOR
            if (LuaDLL.lua_isnumber(L, -1) == 0)
            {
                LuaDLL.luaL_typerror(L, -1, "number");
            }
                        #endif
            uint   uniqueCode = (uint)LuaDLL.lua_tonumber(L, -1);
            byte[] value      = m_TableBytes[uniqueCode];
            if (value != null)
            {
                CBytesConvert.UF_writebytes(buffer, value);
            }

            return(0);
        }