本文整理汇总了C#中IMessageSerializer.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# IMessageSerializer.Deserialize方法的具体用法?C# IMessageSerializer.Deserialize怎么用?C# IMessageSerializer.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMessageSerializer
的用法示例。
在下文中一共展示了IMessageSerializer.Deserialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Time
private void Time(IMessage[] messages, IMessageSerializer serializer) {
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < numberOfIterations; i++)
using (MemoryStream stream = new MemoryStream())
serializer.Serialize(messages, stream);
watch.Stop();
Debug.WriteLine("Serializing: " + watch.Elapsed);
watch.Reset();
MemoryStream s = new MemoryStream();
serializer.Serialize(messages, s);
byte[] buffer = s.GetBuffer();
s.Dispose();
Console.WriteLine(Encoding.ASCII.GetString(buffer));
watch.Start();
object[] result = null;
for (int i = 0; i < numberOfIterations; i++)
using (var forDeserializing = new MemoryStream(buffer))
result = serializer.Deserialize(forDeserializing);
watch.Stop();
Debug.WriteLine("Deserializing: " + watch.Elapsed);
}
示例2: Reserialize
internal static object Reserialize(IMessageSerializer serializer, object message)
{
if (serializer == null)
return message;
var writer = new BinaryTokenStreamWriter();
serializer.Serialize(message, writer);
var bytes = writer.ToByteArray();
var reader = new BinaryTokenStreamReader(bytes);
return serializer.Deserialize(reader);
}
示例3: InvokeMutators
private IMessage InvokeMutators(IMessage message, IMessageSerializer serializer)
{
var messageToSerialize = messageMutator.MutateOutgoing(message);
using (var stream = new MemoryStream())
{
serializer.Serialize(new[] { messageToSerialize }, stream);
stream.Position = 0;
var result = serializer.Deserialize(stream)[0];
return messageMutator.MutateIncoming(result);
}
}
示例4: ListenForMessages
IObservable<object> ListenForMessages(ZmqContext context, string address, IMessageSerializer serializer)
{
return
Observable.Create<object>
(
o =>
{
_socket.Connect(address);
var poller = _scheduler.SchedulePeriodic
(
_pollInterval,
() =>
{
try
{
var msg = _socket.ReceiveMessage(TimeSpan.Zero);
while (msg != null && msg.FrameCount == 3)
{
var typeName = ZmqContext.DefaultEncoding.GetString(msg[1].Buffer);
var type = MessageTypeRegistry.Resolve(typeName);
var data = msg[2].Buffer;
if (type != null)
{
var poco = serializer.Deserialize(data, type);
o.OnNext(poco);
}
msg = _socket.ReceiveMessage(TimeSpan.Zero);
}
}
catch (Exception ex)
{
o.OnError(ex);
}
}
);
return new CompositeDisposable(poller, Disposable.Create(() => _socket.Disconnect(address)));
}
)
.SubscribeOn(_scheduler)
.ObserveOn(_scheduler)
.Publish()
.RefCount();
}