예제 #1
0
        private KLuaValueDef UnPackUp(MemoryStream stream, ArrayList retArray)
        {
            uint         size = 0;
            KLuaValueDef eRet = (KLuaValueDef)stream.ReadByte();

            switch (eRet)
            {
            case KLuaValueDef.eLuaPackNumber:
                size = UnPackupNumber(stream, retArray);
                break;

            case KLuaValueDef.eLuaPackBoolean:
                size = UnPackupBoolean(stream, retArray);
                break;

            case KLuaValueDef.eLuaPackString:
                size = UnPackupString(stream, retArray);
                break;

            case KLuaValueDef.eLuaPackNill:
                size = UnPackNull(stream, retArray);
                break;

            case KLuaValueDef.eLuaPackTable:
                size = UnPackTable(stream, retArray);
                break;
            }
            size += sizeof(byte);
            return(eRet);
        }
예제 #2
0
        private uint UnPackTable(MemoryStream stream, ArrayList retArray)
        {
            BinaryReader read    = new BinaryReader(stream);
            uint         tabSize = read.ReadUInt32();
            uint         tabEnd  = (uint)(stream.Position) + tabSize;
            RemoteTable  luaTab  = new RemoteTable();

            while (stream.Position < tabEnd)
            {
                ArrayList tabKV = new ArrayList();

                KLuaValueDef keyType   = UnPackUp(stream, tabKV);
                KLuaValueDef valueType = UnPackUp(stream, tabKV);

                if (keyType == KLuaValueDef.eLuaPackNumber)
                {
                    int index = (int)tabKV[0];
                    switch (valueType)
                    {
                    case KLuaValueDef.eLuaPackNumber:
                        luaTab[index] = (RemoteInt)((int)tabKV[1]);
                        break;

                    case KLuaValueDef.eLuaPackBoolean:
                        luaTab[index] = (RemoteBool)((bool)tabKV[1]);
                        break;

                    case KLuaValueDef.eLuaPackString:
                        luaTab[index] = (RemoteString)(tabKV[1] as string);
                        break;

                    case KLuaValueDef.eLuaPackTable:
                        luaTab[index] = tabKV[1] as RemoteTable;
                        break;

                    default:
                        log.Error("UnKnow ValueType");
                        break;
                    }
                }
                else
                {
                    string name = tabKV[0] as string;
                    switch (valueType)
                    {
                    case KLuaValueDef.eLuaPackNumber:
                        luaTab[name] = (RemoteInt)((int)tabKV[1]);
                        break;

                    case KLuaValueDef.eLuaPackBoolean:
                        luaTab[name] = (RemoteBool)((bool)tabKV[1]);
                        break;

                    case KLuaValueDef.eLuaPackString:
                        luaTab[name] = (RemoteString)(tabKV[1] as string);
                        break;

                    case KLuaValueDef.eLuaPackTable:
                        luaTab[name] = tabKV[1] as RemoteTable;
                        break;

                    default:
                        log.Error("UnKnow ValueType");
                        break;
                    }
                }
            }
            retArray.Add(luaTab);
            return(tabSize);
        }