Exemple #1
0
        internal void LoadFromStream(Stream st)
        {
            mapDict = new Dictionary <UInt32, string>();

            byte[] readDataResult = new byte[st.Length];
            st.Read(readDataResult, 0, readDataResult.Length);

            IdPak pak = ProtobufHelper.Deserialize <IdPak>(readDataResult);

            foreach (IdPair tPair in pak.idPair)
            {
                mapDict.Add(tPair.idUInt, tPair.idStr);
            }
        }
Exemple #2
0
        public void ProtobufPost()
        {
            var stream = new MemoryStream();

            ProtobufHelper.Serialize(stream, _dtos);
            stream.Seek(0, SeekOrigin.Begin);
            var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "api/Values")
            {
                Content = new StreamContent(stream)
            };

            httpRequestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-protobuf");
            httpRequestMessage.Headers.Add("Accept", "application/x-protobuf");

            // HTTP POST with Protobuf Request Body
            var responseForPost = _protobufHttpClient.SendAsync(httpRequestMessage);

            var result = ProtobufHelper.Deserialize <List <TestDto> >(
                responseForPost.Result.Content.ReadAsStreamAsync().Result);
        }
        public void TestProtobuf()
        {
            var client = _server.CreateClient();
            var dtos   = GetDtos();
            var stream = new MemoryStream();

            ProtobufHelper.Serialize(stream, dtos);
            stream.Seek(0, SeekOrigin.Begin);
            var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "api/Values/Post")
            {
                Content = new StreamContent(stream)
            };

            httpRequestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-protobuf");
            httpRequestMessage.Headers.Add("Accept", "application/x-protobuf");

            // HTTP POST with Protobuf Request Body
            var response = client.SendAsync(httpRequestMessage).Result;

            var result = ProtobufHelper.Deserialize <List <TestDto> >(
                response.Content.ReadAsStreamAsync().Result);

            Assert.True(CompareDtos(dtos, result));
        }
        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("****************************************");
                }
            }
        }
 public static object FromProtoBuf(this byte[] bytes, Type type)
 {
     return(ProtobufHelper.Deserialize(bytes, type));
 }
 public static T FromProtoBuf <T>(this byte[] bytes)
 {
     return(ProtobufHelper.Deserialize <T>(bytes));
 }