public void Execute() { byte[] buffer = { 9, 8, 5, 26, 5, 24, 238, 98, 32, 1 }; var model = RuntimeTypeModel.Create(); model.AutoCompile = false; using (var ms = new MemoryStream(buffer)) { int len = ProtoReader.DirectReadVarintInt32(ms); var resp = (Response)model.Deserialize(ms, null, typeof(Response), len); Assert.Equal(5, resp.Type); Assert.Single(resp.v3dDelta); Assert.Equal(12654, resp.v3dDelta[0].ask); Assert.Equal(1, resp.v3dDelta[0].askSize); } }
public void Execute() { byte[] buffer = { 9, 8, 5, 26, 5, 24, 238, 98, 32, 1 }; var model = TypeModel.Create(false, ProtoCompatibilitySettingsValue.FullCompatibility); model.AutoCompile = false; using (var ms = new MemoryStream(buffer)) { int len = ProtoReader.DirectReadVarintInt32(ms); var resp = (Response)model.Deserialize(ms, null, typeof(Response), len); Assert.AreEqual(5, resp.Type); Assert.AreEqual(1, resp.v3dDelta.Count); Assert.AreEqual(12654, resp.v3dDelta[0].ask); Assert.AreEqual(1, resp.v3dDelta[0].askSize); } }
private void ReadStream(Stream stream, Dictionary <int, int> remoteToLocalRowIds) { var len = 0; if (WithLengthPrefix) { // Read the length of the message from the stream. // DirectReadVarintInt32 calls Stream.ReadByte() which allocates a one byte array on every call - yuck! var header = ProtoReader.DirectReadVarintInt32(stream); len = ProtoReader.DirectReadVarintInt32(stream); } // Allocation of protoreader for each message - blurghh! using (var reader = new ProtoReader(stream, null, null, len)) { int fieldId; while ((fieldId = reader.ReadFieldHeader()) != 0) { if (fieldId == ProtobufOperationTypes.Add) { var rowId = ReadRowId(reader); if (rowId >= 0) { remoteToLocalRowIds.Add(rowId, _table.AddRow()); var dummyFieldId = reader.ReadFieldHeader(); ReadUpdate(remoteToLocalRowIds, reader); } } else if (fieldId == ProtobufOperationTypes.Update) { ReadUpdate(remoteToLocalRowIds, reader); } else if (fieldId == ProtobufOperationTypes.Delete) { var rowId = ReadRowId(reader); if (rowId >= 0) { _table.DeleteRow(remoteToLocalRowIds[rowId]); remoteToLocalRowIds.Remove(rowId); } } } } }
internal void LoadFromStream(Stream st) { /* * if(Application.platform==RuntimePlatform.WindowsEditor || Application.platform==RuntimePlatform.Android) * { * UnityEngine.Object obj = Resources.Load("game"); * TextAsset ta = (TextAsset)obj; * st = new MemoryStream(ta.bytes); * } * else * { * st = new FileStream(Application.streamingAssetsPath+"/"+"game.navigPak",FileMode.Open); * } */ using (st) { ProtoReader pReader = new ProtoReader(st, null, null); navDict = new Dictionary <UInt32, NavigParam>(); long fsSize = st.Length; while (fsSize > 0) { int readHeadSize = ProtoReader.DirectReadVarintInt32(st); fsSize -= 4; byte[] tempHeadByte = ProtoReader.DirectReadBytes(st, (int)readHeadSize); fsSize -= readHeadSize; NavigHead nHead = ProtobufHelper.Deserialize <NavigHead>(tempHeadByte); int bodaySizeHead = ProtoReader.DirectReadVarintInt32(st); byte[] tempBodayByte = ProtoReader.DirectReadBytes(st, bodaySizeHead); fsSize -= bodaySizeHead; NavigationA nA = ProtobufHelper.Deserialize <NavigationA>(tempBodayByte); List <Vector3> v3List = new List <Vector3>(); foreach (Pak.Vector3 tempV3 in nA.frame) { Vector3 tempV = new Vector3(); tempV.x = tempV3.x; tempV.y = tempV3.y; tempV.z = tempV3.z; v3List.Add(tempV); } NavigParam np = new NavigParam(); np.path = v3List; np.timeLength = nHead.cycleTime; navDict.Add(nHead.idUInt, np); // Debug.LogError("****************************************"); // Debug.LogError("HeadDataType====="+nHead.type); // Debug.LogError("HeadDataIdStr===="+nHead.idStr); // Debug.LogError("HeadDateUint====="+nHead.idUInt); // Debug.LogError("HeadDataCyTime=============================================="+nHead.cycleTime); // Debug.LogWarning("BodayListCount="+nA.frame.Count); // Debug.LogError("****************************************"); } } }