本文整理汇总了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);
}
}
示例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;
}
}
//.........这里部分代码省略.........
示例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);
}