當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。