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


C# Serialization.BinaryTokenStreamReader类代码示例

本文整理汇总了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);
        }
开发者ID:jdom,项目名称:orleans,代码行数:25,代码来源:ILBasedSerializerTests.cs

示例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).");
            }
        }
开发者ID:jgelinske,项目名称:orleans,代码行数:31,代码来源:Identifiertests.cs

示例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;
 }
开发者ID:PaulNorth,项目名称:orleans,代码行数:8,代码来源:CustomSerializerTests.cs

示例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);
 }
开发者ID:osjimenez,项目名称:orleans,代码行数:15,代码来源:ILBasedFallbackSerializer.cs

示例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);
        }
开发者ID:Carlm-MS,项目名称:orleans,代码行数:10,代码来源:SerializationTestsUtils.cs

示例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);
        }
开发者ID:cuteant,项目名称:orleans,代码行数:16,代码来源:OrleansJsonSerializer.cs

示例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);
 }
开发者ID:Carlm-MS,项目名称:orleans,代码行数:12,代码来源:StreamTypeSerializationTests.cs

示例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);
        }
开发者ID:rikace,项目名称:Orleankka,代码行数:13,代码来源:OrleansSerialization.cs

示例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);
        }
开发者ID:Applicita,项目名称:Orleankka,代码行数:13,代码来源:ResponseEnvelope.cs

示例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);
        }
开发者ID:Carlm-MS,项目名称:orleans,代码行数:15,代码来源:StreamTypeSerializationTests.cs

示例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;
        }
开发者ID:sbambach,项目名称:orleans,代码行数:18,代码来源:BinaryFormatterSerializer.cs

示例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);
        }
开发者ID:Carlm-MS,项目名称:orleans,代码行数:20,代码来源:StreamTypeSerializationTests.cs

示例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");
        }
开发者ID:PaulNorth,项目名称:orleans,代码行数:11,代码来源:CustomSerializerTests.cs

示例14: TokenFromBytes

 private static StreamSequenceToken TokenFromBytes(byte[] bytes)
 {
     var stream = new BinaryTokenStreamReader(bytes);
     return SerializationManager.Deserialize<StreamSequenceToken>(stream);
 }
开发者ID:PaulNorth,项目名称:orleans,代码行数:5,代码来源:StreamDeliveryFailureEntity.cs

示例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);
 }
开发者ID:DarkHarlock,项目名称:Orleankka,代码行数:6,代码来源:JsonSerializer.cs


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