当前位置: 首页>>代码示例>>C#>>正文


C# Deserializer.Create方法代码示例

本文整理汇总了C#中Deserializer.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Deserializer.Create方法的具体用法?C# Deserializer.Create怎么用?C# Deserializer.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Deserializer的用法示例。


在下文中一共展示了Deserializer.Create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnReceiveFromInternal

        protected void OnReceiveFromInternal(int bytesTransferred, EndPoint endPoint)
        {
            Diag.AddBytesReceived(bytesTransferred);

            int handle;
            using (new ReadLock(rwlock))
            {
                if (!reverseMap.TryGetValue(endPoint, out handle))
                {
                    handle = 0;
                }
            }

            rxBuffer.Stretch(bytesTransferred);
            if (BufferTransform != null)
            {
                try
                {
                    BufferTransform.InverseTransform(rxBuffer, (int)rxBuffer.Length);
                }
                catch (Exception e)
                {
                    Log.Error("{0} {1} buffer inv transform error: {2}", Name, handle, e.Message);
                    return;
                }
            }
            rxBuffer.Rewind();

            var deserializer = new Deserializer(rxBuffer);
            Event retrieved = deserializer.Create();
            if (retrieved == null)
            {
                return;
            }
            else
            {
                try
                {
                    retrieved.Deserialize(deserializer);
                }
                catch (Exception e)
                {
                    Log.Error("{0} {1} error loading event {2}: {3}", Name, handle, retrieved.GetTypeId(), e.ToString());
                    return;
                }

                if (handle != 0)
                {
                    retrieved._Handle = handle;
                }

                Hub.Post(retrieved);

                Diag.IncrementEventsReceived();

                Log.Debug("{0} {1} received event {2}", Name, handle, retrieved);
            }
        }
开发者ID:jaykang920,项目名称:x2clr,代码行数:58,代码来源:AbstractUdpLink.cs

示例2: OnReceiveInternal

        protected void OnReceiveInternal(int bytesTransferred)
        {
            Diag.AddBytesReceived(bytesTransferred);

            Log.Trace("{0} {1} received {2} byte(s)",
                link.Name, InternalHandle, bytesTransferred);

            if (disposed)
            {
                return;
            }

            rxBuffer.Stretch(bytesTransferred);

            if (rxBeginning)
            {
                rxBuffer.Rewind();

                if (!ParseHeader())
                {
                    BeginReceive(true);
                    return;
                }
            }

            // Handle split packets.
            if (rxBuffer.Length < lengthToReceive)
            {
                BeginReceive(false);
                return;
            }

            while (true)
            {
                rxBuffer.MarkToRead(lengthToReceive);

                Log.Trace("{0} {1} marked {2} byte(s) to read",
                    link.Name, InternalHandle, lengthToReceive);

                if (BufferTransform != null && rxTransformReady && rxTransformed)
                {
                    try
                    {
                        BufferTransform.InverseTransform(rxBuffer, lengthToReceive);
                    }
                    catch (Exception e)
                    {
                        Log.Error("{0} {1} buffer inv transform error: {2}",
                            link.Name, InternalHandle, e.Message);
                        goto next;
                    }
                }
                rxBuffer.Rewind();

                Interlocked.Increment(ref rxCounter);

                var deserializer = new Deserializer(rxBuffer);
                Event retrieved = deserializer.Create();
                if ((object)retrieved == null)
                {
                    goto next;
                }
                else
                {
                    try
                    {
                        retrieved.Deserialize(deserializer);
                    }
                    catch (Exception e)
                    {
                        Log.Error("{0} {1} error loading event {2}: {3}",
                            link.Name, InternalHandle, retrieved.GetTypeId(), e.ToString());
                        goto next;
                    }

                    OnEventReceived(retrieved);

                    if (!Process(retrieved))
                    {
                        retrieved._Handle = Handle;

                        link.OnPreprocess(this, retrieved);

                        Hub.Post(retrieved);
                    }
                }
            next:
                rxBuffer.Trim();
                if (rxBuffer.IsEmpty)
                {
                    break;
                }

                if (!ParseHeader() ||
                    rxBuffer.Length < lengthToReceive)
                {
                    BeginReceive(false);
                    return;
                }
            }
//.........这里部分代码省略.........
开发者ID:jaykang920,项目名称:x2clr,代码行数:101,代码来源:LinkSession.cs

示例3: TestPartialSerialization

        public void TestPartialSerialization()
        {
            EventFactory.Register<SampleEvent5>();

            var buffer = new x2.Buffer();

            var cell1 = new SampleCell1 {  // base
                Foo = 9,
                Bar = "hello"
            };
            var cell2 = new SampleCell2 {  // derived
                Foo = 9,
                Bar = "hello",
                Baz = true
            };

            var event1 = new SampleEvent5();  // has base

            // base > base > base
            event1.SampleCell = cell1;
            Serializer serializer = new Serializer(buffer);
            serializer.Write(event1.GetTypeId());
            event1.Serialize(serializer);

            long bufferLength = buffer.Length;

            buffer.Rewind();
            Deserializer deserializer = new Deserializer(buffer);

            var retrieved = deserializer.Create();
            retrieved.Deserialize(deserializer);

            var event11 = retrieved as SampleEvent5;
            Assert.NotNull(event11);

            Assert.AreEqual(event1.SampleCell.Foo, event11.SampleCell.Foo);
            Assert.AreEqual(event1.SampleCell.Bar, event11.SampleCell.Bar);

            buffer.Reset();

            // derived > base > base
            event1.SampleCell = cell2;  // base <= derived
            serializer = new Serializer(buffer);
            serializer.Write(event1.GetTypeId());
            event1.Serialize(serializer);

            Assert.AreEqual(bufferLength, buffer.Length);

            {
                var event2 = new SampleEvent6();  // has derived
                event2.SampleCell = cell2;  // derived <= derived
                var buffer2 = new x2.Buffer();
                serializer = new Serializer(buffer2);
                serializer.Write(event2.GetTypeId());
                event2.Serialize(serializer);
                Assert.Greater(buffer2.Length, buffer.Length);
            }

            buffer.Rewind();
            deserializer = new Deserializer(buffer);

            retrieved = deserializer.Create();
            retrieved.Deserialize(deserializer);

            var event12 = retrieved as SampleEvent5;
            Assert.NotNull(event12);

            Assert.AreEqual(event1.SampleCell.Foo, event12.SampleCell.Foo);
            Assert.AreEqual(event1.SampleCell.Bar, event12.SampleCell.Bar);
        }
开发者ID:jaykang920,项目名称:x2clr,代码行数:70,代码来源:SerializerTests.cs


注:本文中的Deserializer.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。