本文整理汇总了C#中Orleans.Serialization.BinaryTokenStreamReader类的典型用法代码示例。如果您正苦于以下问题:C# BinaryTokenStreamReader类的具体用法?C# BinaryTokenStreamReader怎么用?C# BinaryTokenStreamReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryTokenStreamReader类属于Orleans.Serialization命名空间,在下文中一共展示了BinaryTokenStreamReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ILSerializer_AllowCopiedFieldsToDifferFromSerializedFields
public void ILSerializer_AllowCopiedFieldsToDifferFromSerializedFields()
{
var input = new FieldTest
{
One = 1,
Two = 2,
Three = 3
};
var generator = new ILSerializerGenerator();
var serializers = generator.GenerateSerializer(input.GetType(), f => f.Name != "One", f => f.Name != "Three");
var copy = (FieldTest)serializers.DeepCopy(input);
Assert.Equal(1, copy.One);
Assert.Equal(2, copy.Two);
Assert.Equal(0, copy.Three);
var writer = new BinaryTokenStreamWriter();
serializers.Serialize(input, writer, input.GetType());
var reader = new BinaryTokenStreamReader(writer.ToByteArray());
var deserialized = (FieldTest)serializers.Deserialize(input.GetType(), reader);
Assert.Equal(0, deserialized.One);
Assert.Equal(2, deserialized.Two);
Assert.Equal(3, deserialized.Three);
}
示例2: UniqueKeySerializationShouldReproduceAnIdenticalObject
public void UniqueKeySerializationShouldReproduceAnIdenticalObject()
{
{
var expected = UniqueKey.NewKey(Guid.NewGuid());
BinaryTokenStreamWriter writer = new BinaryTokenStreamWriter();
writer.Write(expected);
BinaryTokenStreamReader reader = new BinaryTokenStreamReader(writer.ToBytes());
var actual = reader.ReadUniqueKey();
Assert.AreEqual(expected, actual, "UniqueKey.Serialize() and UniqueKey.Deserialize() failed to reproduce an identical object (case #1).");
}
{
var kx = random.Next().ToString(CultureInfo.InvariantCulture);
var expected = UniqueKey.NewKey(Guid.NewGuid(), category: UniqueKey.Category.KeyExtGrain, keyExt: kx);
BinaryTokenStreamWriter writer = new BinaryTokenStreamWriter();
writer.Write(expected);
BinaryTokenStreamReader reader = new BinaryTokenStreamReader(writer.ToBytes());
var actual = reader.ReadUniqueKey();
Assert.AreEqual(expected, actual, "UniqueKey.Serialize() and UniqueKey.Deserialize() failed to reproduce an identical object (case #2).");
}
{
var kx = random.Next().ToString(CultureInfo.InvariantCulture) + new String('*', 400);
var expected = UniqueKey.NewKey(Guid.NewGuid(), category: UniqueKey.Category.KeyExtGrain, keyExt: kx);
BinaryTokenStreamWriter writer = new BinaryTokenStreamWriter();
writer.Write(expected);
BinaryTokenStreamReader reader = new BinaryTokenStreamReader(writer.ToBytes());
var actual = reader.ReadUniqueKey();
Assert.AreEqual(expected, actual, "UniqueKey.Serialize() and UniqueKey.Deserialize() failed to reproduce an identical object (case #3).");
}
}
示例3: Deserialize
private static object Deserialize(Type expected, BinaryTokenStreamReader stream)
{
DeserializeCounter++;
var result = new ClassWithCustomSerializer();
result.IntProperty = stream.ReadInt();
result.StringProperty = stream.ReadString();
return result;
}
示例4: Deserialize
/// <summary>
/// Tries to deserialize an item.
/// </summary>
/// <param name="reader">The reader used for binary deserialization</param>
/// <param name="expectedType">The type that should be deserialzied</param>
/// <returns>The deserialized object</returns>
public object Deserialize(Type expectedType, BinaryTokenStreamReader reader)
{
var token = reader.ReadToken();
if (token == SerializationTokenType.Null) return null;
var actualType = this.ReadType(token, reader, expectedType);
var methods = this.serializers.Get(actualType);
var deserializer = methods.Deserialize;
return deserializer(expectedType, reader);
}
示例5: VerifyUsingFallbackSerializer
public static void VerifyUsingFallbackSerializer(object ob)
{
var writer = new BinaryTokenStreamWriter();
SerializationManager.FallbackSerializer(ob, writer, ob.GetType());
var bytes = writer.ToByteArray();
var reader = new BinaryTokenStreamReader(bytes);
var serToken = reader.ReadToken();
Assert.Equal(SerializationTokenType.Fallback, serToken);
}
示例6: Deserialize
/// <summary>
/// Deserializes an object from a binary stream
/// </summary>
/// <param name="expectedType">The type that is expected to be deserialized</param>
/// <param name="reader">The <see cref="BinaryTokenStreamReader"/></param>
/// <returns>The deserialized object</returns>
public object Deserialize(Type expectedType, BinaryTokenStreamReader reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
var str = reader.ReadString();
return JsonConvert.DeserializeObject(str, expectedType, settings);
}
示例7: EventSequenceTokenV2_Serialize_IfNotNull
public void EventSequenceTokenV2_Serialize_IfNotNull()
{
var writer = new BinaryTokenStreamWriter();
var token = new EventSequenceTokenV2(long.MaxValue, int.MaxValue);
EventSequenceTokenV2.Serialize(token, writer, null);
var reader = new BinaryTokenStreamReader(writer.ToByteArray());
var deserialized = EventSequenceTokenV2.Deserialize(typeof(EventSequenceTokenV2), reader) as EventSequenceTokenV2;
Assert.NotNull(deserialized);
Assert.NotSame(token, deserialized);
Assert.Equal(token.EventIndex, deserialized.EventIndex);
Assert.Equal(token.SequenceNumber, deserialized.SequenceNumber);
}
示例8: 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);
}
示例9: Deserialize
internal static object Deserialize(Type unused, BinaryTokenStreamReader stream)
{
byte resultToken = stream.ReadByte();
if (resultToken == ResultToken.Null)
return new ResponseEnvelope(null);
if (resultToken != ResultToken.Some)
throw new NotSupportedException();
var result = MessageEnvelope.Serializer.Deserialize(stream);
return new ResponseEnvelope(result);
}
示例10: AzureQueueBatchContainerV2_Serialize_IfNotNull
public void AzureQueueBatchContainerV2_Serialize_IfNotNull()
{
var container = CreateAzureQueueBatchContainer();
var writer = new BinaryTokenStreamWriter();
AzureQueueBatchContainerV2.Serialize(container, writer, null);
var reader = new BinaryTokenStreamReader(writer.ToByteArray());
var deserialized = AzureQueueBatchContainerV2.Deserialize(typeof(AzureQueueBatchContainer), reader) as AzureQueueBatchContainerV2;
ValidateIdenticalQueueBatchContainerButNotSame(container, deserialized);
writer = new BinaryTokenStreamWriter();
SerializationManager.Serialize(container, writer);
reader = new BinaryTokenStreamReader(writer.ToByteArray());
deserialized = SerializationManager.Deserialize<AzureQueueBatchContainerV2>(reader);
ValidateIdenticalQueueBatchContainerButNotSame(container, deserialized);
}
示例11: Deserialize
public object Deserialize(Type expectedType, BinaryTokenStreamReader reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
var n = reader.ReadInt();
var bytes = reader.ReadBytes(n);
var formatter = new BinaryFormatter();
object retVal = null;
using (var memoryStream = new MemoryStream(bytes))
{
retVal = formatter.Deserialize(memoryStream);
}
return retVal;
}
示例12: EventSequenceTokenV2_DeepCopy_IfNotNull
public void EventSequenceTokenV2_DeepCopy_IfNotNull()
{
var token = new EventSequenceTokenV2(long.MaxValue, int.MaxValue);
var copy = EventSequenceTokenV2.DeepCopy(token) as EventSequenceToken;
Assert.NotNull(copy);
Assert.NotSame(token, copy);
Assert.Equal(token.EventIndex, copy.EventIndex);
Assert.Equal(token.SequenceNumber, copy.SequenceNumber);
var writer = new BinaryTokenStreamWriter();
SerializationManager.Serialize(token, writer);
var bytes = writer.ToByteArray();
var reader = new BinaryTokenStreamReader(bytes);
copy = SerializationManager.Deserialize(reader) as EventSequenceToken;
Assert.NotNull(copy);
Assert.NotSame(token, copy);
Assert.Equal(token.EventIndex, copy.EventIndex);
Assert.Equal(token.SequenceNumber, copy.SequenceNumber);
}
示例13: Serialize_CustomSerializer
public void Serialize_CustomSerializer()
{
var original = new ClassWithCustomSerializer() { IntProperty = -3, StringProperty = "Goodbye" };
var writeStream = new BinaryTokenStreamWriter();
SerializationManager.Serialize(original, writeStream);
Assert.AreEqual(1, ClassWithCustomSerializer.SerializeCounter, "Custom serializer was not called");
var readStream = new BinaryTokenStreamReader(writeStream.ToBytes());
var obj = SerializationManager.Deserialize(readStream);
Assert.AreEqual(1, ClassWithCustomSerializer.DeserializeCounter, "Custom deserializer was not called");
}
示例14: TokenFromBytes
private static StreamSequenceToken TokenFromBytes(byte[] bytes)
{
var stream = new BinaryTokenStreamReader(bytes);
return SerializationManager.Deserialize<StreamSequenceToken>(stream);
}
示例15:
object IMessageSerializer.Deserialize(BinaryTokenStreamReader stream)
{
var bytes = (byte[]) SerializationManager.DeserializeInner(typeof(byte[]), stream);
var json = Encoding.Default.GetString(bytes);
return JsonConvert.DeserializeObject(json, settings);
}