public bool DecodeBuildInTemplate <T>(string path, ref T template) where T : TBase, new()
    {
        path = "BuildIn/" + path;
        TextAsset textAsset = Resources.Load <TextAsset>(path);

        if (textAsset != null)
        {
            byte[] data = textAsset.bytes;

            if (null != data)
            {
                template = new T();
                ThriftSerialize.DeSerialize(template, data);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            Debuger.LogError("error ");
        }
        return(false);
    }
Beispiel #2
0
 public AsyncState DoAsyncTask()
 {
     if (UpdateList == null || UpdateList.Count == 0)
     {
         return(AsyncState.AfterAsync);
     }
     foreach (TBase tbase in UpdateList)
     {
         try
         {
             byte[] bytes = ThriftSerialize.Serialize(tbase);
             if (bytes == null)
             {
                 continue;
             }
             //string sql = string.Format("replace into {0}(id, data) values((@id) ,(@data))");
             //SqliteCommand cmd = SqliteDbAccess.Instance.CreateSqliteCommand();
             //cmd.CommandText = sql;
             //cmd.Parameters.Add(new SqliteParameter("@id", tbase.GetType().FullName));
             //cmd.Parameters.Add(new SqliteParameter("@data", bytes));
             int n = 0;// cmd.ExecuteNonQuery();
             if (n == 0)
             {
                 Debuger.LogError(string.Format("{0} update fail.", tbase.GetType().FullName));
             }
         }
         catch (Exception e)
         {
             Debuger.LogError(e.Message);
         }
     }
     return(AsyncState.AfterAsync);
 }
Beispiel #3
0
 private void SaveParam()
 {
     ChangeDataToInfo(m_ProcessInfo, m_ProcessData);
     //load info from local cache
     byte[] obj = ThriftSerialize.Serialize(m_ProcessInfo);
     PlayerManager.Instance.GetCharBaseData().CharDeatail = obj;
 }
Beispiel #4
0
    public void SaveTerrainEditFileList(TerrainEditorDataArray filedata, TerrainEditorData editorData)
    {
        if (null == filedata)
        {
            filedata          = new TerrainEditorDataArray();
            filedata.DataList = new System.Collections.Generic.List <TerrainEditorData>();
        }

        if (null != editorData)
        {
            bool bIsNeedAddNew = true;
            for (int i = 0; i < filedata.DataList.Count; ++i)
            {
                if (filedata.DataList[i].ID == editorData.ID)
                {
                    filedata.DataList[i] = editorData;
                    bIsNeedAddNew        = false;
                    break;
                }
            }
            if (bIsNeedAddNew)
            {
                filedata.DataList.Add(editorData);
            }
        }

        byte[] data = ThriftSerialize.Serialize(filedata);
        FileUtils.WriteByteFile(m_strDataPath, data);
    }
Beispiel #5
0
    public static void MergeEventControlDataMap(ref EventControlDataMap fileDataMap)
    {
        if (fileDataMap == null || fileDataMap.MapFileData == null)
        {
            fileDataMap             = new EventControlDataMap();
            fileDataMap.MapFileData = new Dictionary <int, EventControlData>();
        }
        EventControlDataMap remoteDataMap             = ConfigManager.Instance.GetEventControlDataMap();
        Dictionary <int, EventControlData> remoteData = remoteDataMap.MapFileData;
        Dictionary <int, EventControlData> localData  = fileDataMap.MapFileData;

        foreach (int ID in remoteData.Keys)
        {
            if (localData.ContainsKey(ID))
            {
            }
            else
            {
                localData.Add(ID, remoteData[ID]);
            }
        }

        byte[] data = ThriftSerialize.Serialize(fileDataMap);
        FileUtils.WriteByteFile(GetEventControDataPath(), data);
    }
Beispiel #6
0
 public static void SaveDifficultyControlDataMap(DifficultyControlDataMap fileDataMap, int gameID, DifficultyControlData fileData)
 {
     //Init Data Map
     if (fileDataMap == null || fileDataMap.MapFileData == null)
     {
         fileDataMap             = new DifficultyControlDataMap();
         fileDataMap.MapFileData = new Dictionary <int, DifficultyControlData>();
     }
     //Init Data
     if (fileData == null || fileData.DifficultyConfig == null)
     {
         fileData = new DifficultyControlData();
         fileData.DifficultyConfig = new Dictionary <string, DifficultyConfig>();
     }
     //Save Data
     if (fileDataMap.MapFileData.ContainsKey(gameID))
     {
         fileDataMap.MapFileData[gameID] = fileData;
     }
     else
     {
         fileDataMap.MapFileData.Add(gameID, fileData);
     }
     //Save File
     byte[] data = ThriftSerialize.Serialize(fileDataMap);
     FileUtils.WriteByteFile(GetDifficultyControlDataPath(), data);
 }
Beispiel #7
0
    public static void DeleteActionEditFile(ActionFileDataArray filedatalist, ActionFileData fileData)
    {
        if (null == filedatalist)
        {
            filedatalist = new ActionFileDataArray();
        }

        if (null == filedatalist.DataList)
        {
            filedatalist.DataList = new List <ActionFileData>();
        }

        for (int i = 0; i < filedatalist.DataList.Count; ++i)
        {
            if (filedatalist.DataList[i].ID == fileData.ID)
            {
                filedatalist.DataList[i] = fileData;
                filedatalist.DataList.RemoveAt(i);
                break;
            }
        }

        byte[] data = ThriftSerialize.Serialize(filedatalist);
        FileUtils.WriteByteFile(GetActionFileDataPath(), data);
    }
Beispiel #8
0
    public static void SaveActionEditFileList(ActionFileDataArray filedatalist, ActionFileData fileData)
    {
        if (null == filedatalist)
        {
            filedatalist = new ActionFileDataArray();
        }

        if (null == filedatalist.DataList)
        {
            filedatalist.DataList = new List <ActionFileData>();
        }

        fileData.TimeStamp = GetTimeStamp();
        bool bIsNeedAddNew = true;

        for (int i = 0; i < filedatalist.DataList.Count; ++i)
        {
            if (filedatalist.DataList[i].ID == fileData.ID)
            {
                filedatalist.DataList[i] = fileData;
                bIsNeedAddNew            = false;
                break;
            }
        }
        if (bIsNeedAddNew)
        {
            filedatalist.DataList.Add(fileData);
        }

        byte[] data = ThriftSerialize.Serialize(filedatalist);
        FileUtils.WriteByteFile(GetActionFileDataPath(), data);
    }
Beispiel #9
0
    private void DownloadRemoteVersionConfig()
    {
        AssetFile remoteVersionFile = new AssetFile(m_strVersionConfigName, "", m_strRemoteAssetServerURL + m_strVersionConfigName);

        List <AssetFile> tmpDownloadList = new List <AssetFile>();

        tmpDownloadList.Add(remoteVersionFile);

        //trigger download remote versin config
        AssetsDownloader_Sync.Instance.BeginDownload(
            tmpDownloadList,
            (file, fileInfo) =>
        {
            m_RemoteVersionConfig = new VersionConfig();
            ThriftSerialize.DeSerialize(m_RemoteVersionConfig, file);
        },
            (e, fileInfo) =>
        {
            m_CompleteCallBack(false, e.Message);
        },
            (process, fileInfo) =>
        {
        },
            () =>
        {
            if (null == m_RemoteVersionConfig || m_RemoteVersionConfig.VersionList == null)
            {
                m_CompleteCallBack(false, "");
            }
            else
            {
                CompareVersion();
            }
        });
    }
Beispiel #10
0
    public void ConvertToByteData()
    {
        try
        {
            string xmlData = FileUtils.ReadStringFile(m_strDataOutputPath + "/" + m_strXmlName);

            if (string.IsNullOrEmpty(xmlData))
            {
                Tip("xml 文件为空");
                return;
            }

            TrunkConfigTable table = new TrunkConfigTable();
            table.TrunkConfigXml = xmlData;

            byte[] data = ThriftSerialize.Serialize(table);
            FileUtils.WriteByteFile(m_strDataOutputPath + "/" + m_strByteName, data);
        }
        catch (Exception e)
        {
            Debug.LogException(e);
            Tip(e.Message);
            throw;
        }
    }
Beispiel #11
0
    // whether have conflict
    public static bool CombineActionEditFileList(ActionFileDataArray filedatalist, out Dictionary <int, ActionFileData> conflictDataMap)
    {
        // Get Local Data
        Dictionary <int, ActionFileData> localDataMap = new Dictionary <int, ActionFileData>();

        // Conflict Value
        conflictDataMap = new Dictionary <int, ActionFileData>();
        if (filedatalist != null && filedatalist.DataList != null)
        {
            foreach (ActionFileData value in filedatalist.DataList)
            {
                if (!localDataMap.ContainsKey(value.ID))
                {
                    localDataMap.Add(value.ID, value);
                }
                else
                {
                    Debug.LogWarning("本地Action ID 有冲突!");
                }
            }
        }
        // Get Remote Data
        ActionFileDataArray downloadData = ConfigManager.Instance.GetActionFileDataArray();

        if (downloadData != null && downloadData.DataList != null)
        {
            foreach (ActionFileData value in downloadData.DataList)
            {
                if (!localDataMap.ContainsKey(value.ID))
                {
                    localDataMap.Add(value.ID, value);
                }
                else
                {
                    if (CheckConflcit(localDataMap[value.ID], value))
                    {
                        conflictDataMap.Add(value.ID, value);
                    }
                }
            }
        }
        // Sycn Data to Local
        if (localDataMap.Count > 0)
        {
            filedatalist          = new ActionFileDataArray();
            filedatalist.DataList = new List <ActionFileData>(localDataMap.Values);
            filedatalist.DataList.Sort(SortFileByID);
            byte[] data = ThriftSerialize.Serialize(filedatalist);
            FileUtils.WriteByteFile(GetActionFileDataPath(), data);
        }
        // return
        if (conflictDataMap.Count > 0)
        {
            return(true);
        }
        return(false);
    }
Beispiel #12
0
    public static void BackupEditFileList(string path)
    {
        ActionFileDataArray filedatalist = ConfigManager.Instance.GetActionFileDataArray();

        if (filedatalist != null && filedatalist.DataList != null)
        {
            filedatalist.DataList.Sort(SortFileByID);
            byte[] data = ThriftSerialize.Serialize(filedatalist);
            FileUtils.WriteByteFile(path + "actionConfig_txtpkg.bytes", data);
        }
    }
Beispiel #13
0
 public static void ReplaceEditFileList(ActionFileDataArray filedatalist)
 {
     filedatalist = ConfigManager.Instance.GetActionFileDataArray();
     if (filedatalist != null && filedatalist.DataList != null)
     {
         Debug.LogWarning("本地所有文件被掩盖");
         filedatalist.DataList.Sort(SortFileByID);
         byte[] data = ThriftSerialize.Serialize(filedatalist);
         FileUtils.WriteByteFile(GetActionFileDataPath(), data);
     }
 }
Beispiel #14
0
    public static void SyncActionEditFileList(ActionFileDataArray filedatalist)
    {
        // Get Local Data
        Dictionary <int, ActionFileData> localDataMap = new Dictionary <int, ActionFileData>();

        if (filedatalist != null && filedatalist.DataList != null)
        {
            foreach (ActionFileData value in filedatalist.DataList)
            {
                if (!localDataMap.ContainsKey(value.ID))
                {
                    localDataMap.Add(value.ID, value);
                }
                else
                {
                    Debug.LogWarning("本地Action ID 有冲突!");
                }
            }
        }
        // Get Remote Data
        ActionFileDataArray downloadData = ConfigManager.Instance.GetActionFileDataArray();

        if (downloadData != null && downloadData.DataList != null)
        {
            foreach (ActionFileData value in downloadData.DataList)
            {
                if (!localDataMap.ContainsKey(value.ID))
                {
                    localDataMap.Add(value.ID, value);
                }
                else
                {
                    if (CheckConflcit(localDataMap[value.ID], value))
                    {
                        localDataMap.Remove(value.ID);
                        localDataMap.Add(value.ID, value);
                        Debug.LogWarning("远程的ActionFile与本地有冲突,本地文件已被覆盖!");
                    }
                }
            }
        }
        // Sycn Data to Local
        if (localDataMap.Count > 0)
        {
            filedatalist          = new ActionFileDataArray();
            filedatalist.DataList = new List <ActionFileData>(localDataMap.Values);
            filedatalist.DataList.Sort(SortFileByID);
            byte[] data = ThriftSerialize.Serialize(filedatalist);
            FileUtils.WriteByteFile(GetActionFileDataPath(), data);
        }
    }
Beispiel #15
0
        private ResponseMessage Decode(Stream responseStream)
        {
            ByteBuffer buffer = ByteBuffer.Allocate(512);

            byte[] tempBytes = new byte[256];
            while (true)
            {
                int readLen = responseStream.Read(tempBytes, 0, tempBytes.Length);
                if (readLen <= 0)
                {
                    break;
                }
                buffer.WriteBytes(tempBytes);
            }

            ResponseMessage responseMessage = new ResponseMessage();

            responseMessage.MessageId  = buffer.ReadInt();
            responseMessage.StatusCode = HttpStatusCode.OK;

            TBase message = ThriftMessageHelper.GetResponseMessage(responseMessage.MessageId);

            if (message == null)
            {
                Debuger.LogError("don't support response messageId:" + responseMessage.MessageId);
                return(null);
            }

            byte[] headerBytes = new byte[buffer.ReadInt()];
            buffer.ReadBytes(headerBytes, 0, headerBytes.Length);

            byte[] messageBytes = new byte[buffer.ReadInt()];
            buffer.ReadBytes(messageBytes, 0, messageBytes.Length);

            byte[] eventListBytes = new byte[buffer.ReadInt()];
            buffer.ReadBytes(eventListBytes, 0, eventListBytes.Length);

            responseMessage.Header = new Header();
            ThriftSerialize.DeSerialize(responseMessage.Header, headerBytes);

            responseMessage.Message = message;
            ThriftSerialize.DeSerialize(message, messageBytes);

            responseMessage.EventList = new MEventList();
            ThriftSerialize.DeSerialize(responseMessage.EventList, eventListBytes);


            return(responseMessage);
        }
    public static bool DecodePersonalDataTemplate <T>(string path, ref T template) where T : TBase, new()
    {
        byte[] data = FileUtils.ReadByteFile(path);

        if (null != data)
        {
            template = new T();
            ThriftSerialize.DeSerialize(template, data);
            return(true);
        }
        else
        {
            return(false);
        }
    }
Beispiel #17
0
 public void TrySetConfig(string path, TBase value)
 {
     if (m_ConfigPool.ContainsKey(path))
     {
         m_ConfigPool[path] = value;
     }
     else
     {
         m_ConfigPool.Add(path, value);
     }
     //save to file
     FileUtils.EnsureFolder(GetConfigPath() + path);
     byte[] buffer = ThriftSerialize.Serialize(value);
     FileUtils.WriteByteFile(GetConfigPath() + path, buffer);
 }
Beispiel #18
0
        private byte[] Encode(Header header, TBase message)
        {
            byte[] headerBytes = ThriftSerialize.Serialize(header);

            byte[] messageBytes = ThriftSerialize.Serialize(message);

            ByteBuffer buffer = ByteBuffer.Allocate(512);

            buffer.WriteInt(ThriftMessageHelper.GetMessageId(message));
            buffer.WriteInt(headerBytes.Length);
            buffer.WriteBytes(headerBytes);
            buffer.WriteInt(messageBytes.Length);
            buffer.WriteBytes(messageBytes);

            return(buffer.ToArray());
        }
Beispiel #19
0
    private void UpdateTerrainConfig()
    {
        TerrainEditorDataArray newList = new TerrainEditorDataArray();

        newList.DataList = new List <TerrainEditorData>();

        TerrainEditorDataArray remoteConfig = ConfigManager.Instance.GetTerrainEditorDataArray();
        TerrainEditorDataArray localConfig  = GetTerrainEditFileList();

        if (null == remoteConfig || remoteConfig.DataList == null || remoteConfig.DataList.Count == 0)
        {
            return;
        }

        if (remoteConfig != null || remoteConfig.DataList != null)
        {
            foreach (var elemRemote in remoteConfig.DataList)
            {
                //add remote
                newList.DataList.Add(elemRemote);
            }
        }

        if (null != localConfig && null != localConfig.DataList)
        {
            foreach (var elemLocal in localConfig.DataList)
            {
                bool isExistInRemote = false;
                foreach (var elemRemote in remoteConfig.DataList)
                {
                    if (elemLocal.ID == elemRemote.ID)
                    {
                        isExistInRemote = true;
                        break;
                    }
                }
                if (!isExistInRemote)
                {
                    //add local
                    newList.DataList.Add(elemLocal);
                }
            }
        }

        byte[] data = ThriftSerialize.Serialize(newList);
        FileUtils.WriteByteFile(m_strDataPath, data);
    }
    public void EncodeGamePackage(object messageBody)
    {
        try
        {
            // clear send buffer
            ResetSendBuffer();

            //
            int messageId = 0;
            if (!m_MessageMapTypeToId.TryGetValue(messageBody.GetType(), out messageId))
            {
                Debug.LogError("Can't encode message " + messageId);
                return;
            }

            // push message id
            Array.Copy(ByteArrayUtil.intToBytes(messageId), 0, m_SendBuffer, m_SendBufferSize, 4);
            m_SendBufferSize += 4;

            // push prefix
            m_SendBufferSize += 4;

            //push header (default length = 0,body = null)
            Array.Copy(ByteArrayUtil.shortToByteArray(0), 0, m_SendBuffer, m_SendBufferSize, 2);
            m_SendBufferSize += 2;

            // push message body length
            TBase  Message     = messageBody as TBase;
            byte[] tmpSendBody = ThriftSerialize.Serialize(Message);
            Array.Copy(ByteArrayUtil.intToBytes(tmpSendBody.Length), 0, m_SendBuffer, m_SendBufferSize, 4);
            m_SendBufferSize += 4;

            Array.Copy(tmpSendBody, 0, m_SendBuffer, m_SendBufferSize, tmpSendBody.Length);
            m_SendBufferSize += tmpSendBody.Length;

            Debug.Log("Send msg:" + messageBody.ToString());
        }
        catch (Exception e)
        {
            Debug.LogError("Error on encode game package ");
            Debug.LogException(e);
        }
    }
Beispiel #21
0
    public static void MergeActionEditFileList(ActionFileDataArray filedatalist, Dictionary <int, ActionFileData> conflictDataMap)
    {
        // Get Local Data
        Dictionary <int, ActionFileData> localDataMap = new Dictionary <int, ActionFileData>();

        if (filedatalist != null && filedatalist.DataList != null)
        {
            foreach (ActionFileData value in filedatalist.DataList)
            {
                if (!localDataMap.ContainsKey(value.ID))
                {
                    localDataMap.Add(value.ID, value);
                }
                else
                {
                    Debug.LogWarning("本地Action ID 有冲突!");
                }
            }
        }
        // Merge Data
        if (conflictDataMap != null)
        {
            foreach (int key in conflictDataMap.Keys)
            {
                if (localDataMap.ContainsKey(key))
                {
                    localDataMap.Remove(key);
                    localDataMap.Add(key, conflictDataMap[key]);
                    Debug.LogWarning("冲突解决,本地文件 : " + key.ToString() + " 已被覆盖!");
                }
            }
        }
        // Sycn Data to Local
        if (localDataMap.Count > 0)
        {
            filedatalist          = new ActionFileDataArray();
            filedatalist.DataList = new List <ActionFileData>(localDataMap.Values);
            filedatalist.DataList.Sort(SortFileByID);
            byte[] data = ThriftSerialize.Serialize(filedatalist);
            FileUtils.WriteByteFile(GetActionFileDataPath(), data);
        }
    }
    public void DecodeStreamAssetTemplate <T>(string path, Action <bool, T> callBack) where T : TBase, new()
    {
        Action <WWW> callBackdef = (www) =>
        {
            byte[] data = www.bytes;

            if (null != data)
            {
                T template = new T();
                ThriftSerialize.DeSerialize(template, data);
                callBack(true, template);
            }
            else
            {
                callBack(false, new T());
            }
        };

        StartCoroutine(LoadWWW(path, callBackdef));
    }
        public object Decode(NetWork.ByteBuffer buffer)
        {
            CharacterDataSnapshot data = new CharacterDataSnapshot();

            byte flag = FLAG_END;

            do
            {
                flag = buffer.ReadByte();

                switch (flag)
                {
                case FLAG_VERSION:
                    data.Version = buffer.ReadLong();
                    break;

                case FLAG_DATA_LIST:
                {
                    int size = buffer.ReadShort();
                    if (size == 0)
                    {
                        continue;
                    }
                    List <TBase> list = new List <TBase>(size);
                    data.DataList = list;
                    for (int i = 0; i < size; i++)
                    {
                        string className  = buffer.ReadString();
                        byte[] tbaseBytes = new byte[buffer.ReadInt()];
                        buffer.ReadBytes(tbaseBytes, 0, tbaseBytes.Length);
                        TBase tbase = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(className, false) as TBase;
                        ThriftSerialize.DeSerialize(tbase, tbaseBytes);
                        list.Add(tbase);
                    }
                    break;
                }
                }
            }while(flag != FLAG_END);

            return(data);
        }
        public void Encode(NetWork.ByteBuffer buffer, object value)
        {
            CharacterDataSnapshot data = value as CharacterDataSnapshot;

            buffer.WriteByte(FLAG_VERSION);
            buffer.WriteLong(data.Version);
            buffer.WriteByte(FLAG_DATA_LIST);

            int size = data.DataList != null ? data.DataList.Count : 0;

            buffer.WriteShort((short)size);
            if (size > 0)
            {
                foreach (TBase tbase in data.DataList)
                {
                    buffer.WriteString(tbase.GetType().FullName);
                    byte[] tbaseBytes = ThriftSerialize.Serialize(tbase);
                    buffer.WriteInt(tbaseBytes.Length);
                    buffer.WriteBytes(tbaseBytes);
                }
            }

            buffer.WriteByte(FLAG_END);
        }
Beispiel #25
0
    private void LoadParam()
    {
        //load info from local cache
        byte[] obj = PlayerManager.Instance.GetCharBaseData().CharDeatail;

        m_ProcessInfo = new PlayerProcessInfo();
        m_ProcessData = new PlayerProcessData();


        if (null != obj)
        {
            ThriftSerialize.DeSerialize(m_ProcessInfo, obj);
            ChangeInfoToData(m_ProcessInfo, m_ProcessData);
        }
        else
        {
            m_ProcessData.m_PlayerTransform  = new PlayerProcessData.TransformData();
            m_ProcessData.m_NpcTransformList = new Dictionary <int, PlayerProcessData.TransformData>();
        }
        if (m_bIsDebugMode)
        {
            m_ProcessData.m_bIsResumeScene = false;
        }
    }
Beispiel #26
0
 public static void SaveData(TBase data, string savePath)
 {
     byte[] fileData = ThriftSerialize.Serialize(data);
     FileUtils.WriteByteFile(savePath, fileData);
 }
Beispiel #27
0
 //Save Data
 public static void SaveDefaultUserTalentMap(DefaultUserTalent fileDataMap)
 {
     byte[] data = ThriftSerialize.Serialize(fileDataMap);
     FileUtils.WriteByteFile(GetDefaultUserTalentDataPath(), data);
 }
    private int DecodeGamePackage(int index, int size)
    {
        m_bIsWaitingPkgComplete = false;

        int initIndex = index;

        if (IsOutOfSize(index, size, 4))
        {
            m_bIsWaitingPkgComplete = true;
            return(initIndex);
        }
        //decode message id
        int messageId = ByteArrayUtil.bytesToInt(m_DecodingBuffer.ToArray(), index);

        index += 4;

        if (IsOutOfSize(index, size, 4))
        {
            m_bIsWaitingPkgComplete = true;
            return(initIndex);
        }
        //skip header
        index += 4;

        if (IsOutOfSize(index, size, 2))
        {
            m_bIsWaitingPkgComplete = true;
            return(initIndex);
        }
        short headerLength = ByteArrayUtil.bytesToShort(m_DecodingBuffer.ToArray(), index);

        index += 2;

        if (IsOutOfSize(index, size, headerLength))
        {
            m_bIsWaitingPkgComplete = true;
            return(initIndex);
        }
        //skip header
        index += headerLength;

        if (IsOutOfSize(index, size, 4))
        {
            m_bIsWaitingPkgComplete = true;
            return(initIndex);
        }
        //get message length
        int messageLength = ByteArrayUtil.bytesToInt(m_DecodingBuffer.ToArray(), index);

        index += 4;

        if (IsOutOfSize(index, size, messageLength))
        {
            m_bIsWaitingPkgComplete = true;
            return(initIndex);
        }
        byte[] messageBody = new byte[messageLength];
        Array.Copy(m_DecodingBuffer.ToArray(), index, messageBody, 0, messageLength);

        //update index
        index += messageLength;

        TBase message = null;
        Type  tmpType;

        if (!m_MessageMapIdToType.TryGetValue(messageId, out tmpType))
        {
            Debug.LogError("Can't decode message " + messageId);
            //return -1;
            return(index);
        }
        message = Activator.CreateInstance(tmpType) as TBase;
        ThriftSerialize.DeSerialize(message, messageBody);

        //broad cast
        MessageDispatcher.Instance.BroadcastMessage(new MessageObject(messageId, message));

        Debug.Log("Rec msg:" + message.ToString());

        return(index);
    }