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); }
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(); } }); }
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); } }
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); }
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; } }
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); }