示例#1
0
 private static Dictionary<int, string> UnpackDictionary(Unpacker unpacker)
 {
     int length = unpacker.UnpackMap();
     var dict = new Dictionary<int, string>(length);
     for (int i = 0; i < length; i++)
     {
         dict.Add(unpacker.UnpackInt(), unpacker.UnpackString());
     }
     return dict;
 }
        protected internal override object UnpackFromCore( Unpacker unpacker )
        {
            if ( !unpacker.IsArrayHeader )
            {
                throw SerializationExceptions.NewIsNotArrayHeader();
            }

            var instance = Array.CreateInstance( this.Traits.ElementType, UnpackHelpers.GetItemsCount( unpacker ) );
            this.UnpackToCore( unpacker, instance );
            return instance;
        }
		public static Boolean? UnpackNullableBooleanValue( Unpacker unpacker, Type objectType, String memberName )
		{
			try
			{
				Boolean? result;
				if ( !unpacker.ReadNullableBoolean( out result ) )
				{
					throw SerializationExceptions.NewFailedToDeserializeMember( objectType, memberName, null );
				}

				return result;
			}
			catch ( MessageTypeException ex )
			{
				throw SerializationExceptions.NewFailedToDeserializeMember( objectType, memberName, ex );
			}
		}
		public static Boolean UnpackBooleanValue( Unpacker unpacker, Type objectType, String memberName )
		{
			if ( unpacker == null )
			{
				SerializationExceptions.ThrowArgumentNullException( "unpacker" );
			}

			if ( objectType == null )
			{
				SerializationExceptions.ThrowArgumentNullException( "objectType" );
			}

			if ( memberName == null )
			{
				SerializationExceptions.ThrowArgumentNullException( "memberName" );
			}

#if ASSERT
			Contract.Assert( unpacker != null );
			Contract.Assert( objectType != null );
			Contract.Assert( memberName != null );
#endif // ASSERT

			// ReSharper disable once RedundantAssignment
			var ctx = default( UnpackerTraceContext );
			InitializeUnpackerTrace( unpacker, ref ctx );

			try
			{
				Boolean result;
				if ( !unpacker.ReadBoolean( out result ) )
				{
					SerializationExceptions.ThrowFailedToDeserializeMember( objectType, memberName, null );
				}

				Trace( ctx, "ReadDirect", unpacker, memberName );

				return result;
			}
			catch ( MessageTypeException ex )
			{
				SerializationExceptions.ThrowFailedToDeserializeMember( objectType, memberName, ex );
				return default( Boolean ); // never reaches.
			}
		}
示例#5
0
        public void TestReadFromFile()
        {
            using (var stream = new FileStream(@"TestFiles\test.mpac", FileMode.Open))
            {
                var unpacker = new Unpacker(stream);

                Assert.AreEqual(
                    new List<long>
                        {
                            0, 1, -1, -123, 12345678, -31, -128, -65535, -(1L << 16), -(1L << 24), 31, 255, 256, (1L << 16),
                            (1L << 24), (1L << 32)
                        }, unpacker.UnpackListOfObjects());

                Assert.AreEqual(
                    new List<double>
                        {
                            0.0, -0.0, 1.0, -1.0, 3.40282347E+38, -3.40282347E+38, 1.7976931348623157E+308, -1.7976931348623157E+308,
                            double.NaN, double.PositiveInfinity, double.NegativeInfinity
                        }, unpacker.UnpackListOfObjects());

                Assert.AreEqual(0xffffffffffffffff, unpacker.UnpackULong());
                Assert.AreEqual(null, unpacker.UnpackNull());
                Assert.AreEqual(true, unpacker.UnpackBool());
                Assert.AreEqual(false, unpacker.UnpackBool());

                Assert.AreEqual(Enumerable.Range(1, 65535).ToList(), unpacker.UnpackListOfObjects());
                Assert.AreEqual(Enumerable.Range(1, 66000).ToList(), unpacker.UnpackListOfObjects());

                TestPackUnpack.AssertDictionariesEqual(
                    new Dictionary<int, bool> {{1, true}, {10, false}, {-127, true}}, unpacker.UnpackDictionary());

                TestPackUnpack.AssertDictionariesEqual(
                    Enumerable.Range(1, 65536).ToDictionary(v => v, v => v * 2), unpacker.UnpackDictionary());

                TestPackUnpack.AssertDictionariesEqual(
                    new Dictionary<int, string> { { 1, "qwerty" }, { 2, "zxc" }, { 5, "" }, {6, null} }, UnpackDictionary(unpacker));
            }
        }
 protected internal override object UnpackFromCore(Unpacker unpacker)
 {
     var instance = this._createInstanceWithCapacity == null ? this._createInstance() : this._createInstanceWithCapacity(UnpackHelpers.GetItemsCount(unpacker));
     this.UnpackTo(unpacker, instance);
     return instance;
 }
示例#7
0
		/// <summary>
		///		Clears the dispatch context information.
		/// </summary>
		internal void ClearDispatchContext()
		{
			this.MethodName = null;
			this.MessageType = MessageType.Response; // Invalid value.
			if ( this._argumentsUnpacker != null )
			{
				this._argumentsUnpacker.Dispose();
				this._argumentsUnpacker = null;
			}

			this.ArgumentsBuffer.SetLength( 0 );
			this.ClearSessionId();
		}
            public void UnpackTo(Unpacker unpacker, object collection)
            {
                if (unpacker == null)
                {
                    throw new ArgumentNullException("unpacker");
                }

                if (collection == null)
                {
                    throw new ArgumentNullException("collection");
                }

                throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, "This operation is not supported by '{0}'.", this.GetType()));
            }
示例#9
0
 /// <summary>
 ///		Deserialize object with specified <see cref="Unpacker"/> asynchronously.
 /// </summary>
 /// <param name="unpacker"><see cref="Unpacker"/> which unpacks values of resulting object tree.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
 /// <returns>
 ///		A <see cref="Task"/> that represents the asynchronous operation.
 ///		The value of the <c>TResult</c> parameter contains the deserialized object.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 ///		<paramref name="unpacker"/> is <c>null</c>.
 /// </exception>
 /// <exception cref="System.Runtime.Serialization.SerializationException">
 ///		Failed to deserialize object.
 /// </exception>
 /// <exception cref="MessageTypeException">
 ///		Failed to deserialize object due to invalid stream.
 /// </exception>
 /// <exception cref="InvalidMessagePackStreamException">
 ///		Failed to deserialize object due to invalid stream.
 /// </exception>
 /// <exception cref="NotSupportedException">
 ///		The type of deserializing is not serializable even if it can be serialized.
 /// </exception>
 /// <remarks>
 ///		You must call <see cref="Unpacker.Read()"/> at least once in advance.
 ///		Or, you will get a default value of the object.
 /// </remarks>
 /// <seealso cref="Capabilities"/>
 public Task <object> UnpackFromAsync(Unpacker unpacker, CancellationToken cancellationToken)
 {
     return(this.InternalUnpackFromAsync(unpacker, cancellationToken));
 }
		internal abstract Task InternalUnpackToAsync( Unpacker unpacker, object collection, CancellationToken cancellationToken );
        private void UnpackFromMap(Unpacker unpacker, ref object instance)
        {
            while (unpacker.Read())
            {
                var memberName = GetMemberName(unpacker);
                int index;
                if (!this._indexMap.TryGetValue(memberName, out index))
                {
                    // Drains unused value.
                    if (!unpacker.Read())
                    {
                        throw SerializationExceptions.NewUnexpectedEndOfStream();
                    }

                    // TODO: unknown member handling.

                    continue;
                }

                // Fetches value
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewUnexpectedEndOfStream();
                }

                if (unpacker.LastReadData.IsNil)
                {
                    switch (this._nilImplications[index])
                    {
                        case NilImplication.Null:
                            {
                                this._memberSetters[index](ref instance, null);
                                continue;
                            }
                        case NilImplication.MemberDefault:
                            {
                                continue;
                            }
                        case NilImplication.Prohibit:
                            {
                                throw SerializationExceptions.NewNullIsProhibited(this._memberNames[index]);
                            }
                    }
                }

                if (unpacker.IsArrayHeader || unpacker.IsMapHeader)
                {
                    using (var subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        this.UnpackMemberInMap(subtreeUnpacker, ref instance, index);
                    }
                }
                else
                {
                    this.UnpackMemberInMap(unpacker, ref instance, index);
                }
            }
        }
 /// <summary>
 ///		Deserialize object with specified <see cref="Unpacker"/>.
 /// </summary>
 /// <param name="unpacker"><see cref="Unpacker"/> which unpacks values of resulting object tree. This value will not be <c>null</c>.</param>
 /// <returns>Deserialized object.</returns>
 /// <exception cref="SerializationException">
 ///		Failed to deserialize object due to invalid unpacker state, stream content, or so.
 /// </exception>
 /// <exception cref="MessageTypeException">
 ///		Failed to deserialize object due to invalid unpacker state, stream content, or so.
 /// </exception>
 /// <exception cref="InvalidMessagePackStreamException">
 ///		Failed to deserialize object due to invalid unpacker state, stream content, or so.
 /// </exception>
 /// <exception cref="NotSupportedException">
 ///		<typeparamref name="T"/> is abstract type.
 /// </exception>
 protected internal abstract T UnpackFromCore(Unpacker unpacker);
		internal abstract void InternalUnpackTo( Unpacker unpacker, object collection );
示例#14
0
        /// <summary> The entry point. </summary>
        static void Main()
        {
            System.Console.Title = EClientApplicationName.WarThunderPresetRandomizer;
            var defaultColor = ConsoleColor.Gray;

            var requiredSettings = new List <string>
            {
                nameof(Settings.WarThunderLocation),
                nameof(Settings.KlensysWarThunderToolsLocation),
            };

            try
            {
                var loggers = new IConfiguredLogger[]
                {
                    new ConfiguredNLogger(ELoggerName.FileLogger, new ExceptionFormatter(), ESubdirectory.Logs),
                    new ConfiguredNLogger(ELoggerName.ConsoleLogger, new ExceptionFormatter()),
                };
                var fileManager           = new WarThunderFileManager(loggers);
                var fileReader            = new WarThunderFileReader(loggers);
                var settingsManager       = new WarThunderSettingsManager(fileManager, EConsoleClientFile.Settings, requiredSettings, loggers);
                var parser                = new Parser(loggers);
                var unpacker              = new Unpacker(fileManager, loggers);
                var dataRepositoryFactory = new DataRepositoryFactoryWarThunder(loggers);
                var converter             = new Converter(loggers);
                var jsonHelper            = new WarThunderJsonHelper(loggers);
                var csvDeserializer       = new CsvDeserializer(loggers);
                var randomiser            = new CustomRandomiser(loggers);
                var vehicleSelector       = new VehicleSelector(randomiser, loggers);
                var presetGenerator       = new PresetGenerator(randomiser, vehicleSelector, loggers);

                using (var manager = new Manager(fileManager, fileReader, settingsManager, parser, unpacker, converter, jsonHelper, csvDeserializer, dataRepositoryFactory, randomiser, vehicleSelector, presetGenerator, true, false, false, loggers))
                {
                    manager.RemoveOldLogFiles();
                    manager.InitializeGameClientVersion();

                    while (!settingsManager.WarThunderLocationIsValid())
                    {
                        System.Console.Write(EConsoleUiLogMessage.SelectValidLocation.FormatFluently(EApplicationName.WarThunder));
                        settingsManager.Save(nameof(Settings.WarThunderLocation), System.Console.ReadLine());
                    }
                    while (!settingsManager.KlensysWarThunderToolLocationIsValid())
                    {
                        System.Console.Write(EConsoleUiLogMessage.SelectValidLocation.FormatFluently(EApplicationName.KlensysWarThunderTools));
                        settingsManager.Save(nameof(Settings.KlensysWarThunderToolsLocation), System.Console.ReadLine());
                    }
                    System.Console.WriteLine();

                    manager.CacheData();

                    while (true)
                    {
                        var specification = ParseSpecification
                                            (
                            TakeSpecificationInput(),
                            manager
                            .ResearchTrees
                            .SelectMany(nationResearchTreeKeyValuePair => nationResearchTreeKeyValuePair.Value)
                            .SelectMany(branchKeyValuePair => branchKeyValuePair.Value)
                            .SelectMany(rankKeyValuePair => rankKeyValuePair.Value)
                            .Select(rankVehicleKeyValuePair => rankVehicleKeyValuePair.Value.GaijinId)
                                            );

                        foreach (var vehicle in manager.GeneratePrimaryAndFallbackPresets(specification)[EPreset.Primary])
                        {
                            System.Console.ForegroundColor = !vehicle.IsResearchable
                                ? ConsoleColor.Yellow
                                : ConsoleColor.White;

                            System.Console.WriteLine($"\t {vehicle.BattleRatingFormatted[specification.GameMode]} {vehicle.GaijinId}");
                        }

                        System.Console.ForegroundColor = defaultColor;
                    }
                }
            }
            catch
            {
                System.Console.Write($"\n{ECoreLogMessage.AnErrorHasOccurred} {EConsoleUiLogMessage.PressAnyKeyToExit} ");
                System.Console.ReadKey(true);
                Environment.Exit(0);
            }
        }
 protected internal override T UnpackFromCore(Unpacker unpacker)
 {
     return(this._unpackFromCore(this._context, unpacker));
 }
        protected internal override async Task <KeyValuePair <TKey, TValue> > UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken)
        {
            if (!await unpacker.ReadAsync(cancellationToken).ConfigureAwait(false))
            {
                SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker);
            }

            var key = unpacker.LastReadData.IsNil ? default(TKey) : await this._keySerializer.UnpackFromAsyncCore(unpacker, cancellationToken).ConfigureAwait(false);

            if (!await unpacker.ReadAsync(cancellationToken).ConfigureAwait(false))
            {
                SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker);
            }

            var value = unpacker.LastReadData.IsNil ? default(TValue) : await this._valueSerializer.UnpackFromAsyncCore(unpacker, cancellationToken).ConfigureAwait(false);

            return(new KeyValuePair <TKey, TValue>(key, value));
        }
示例#17
0
        protected internal override async Task <NameValueCollection> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken)
        {
            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(unpacker);
            }

            var count      = UnpackHelpers.GetItemsCount(unpacker);
            var collection = new NameValueCollection(count);

            await UnpackToAsyncCore(unpacker, collection, count, cancellationToken).ConfigureAwait(false);

            return(collection);
        }
 /// <summary>
 ///		Deserialize collection items with specified <see cref="Unpacker"/> and stores them to <paramref name="collection"/>.
 /// </summary>
 /// <param name="unpacker"><see cref="Unpacker"/> which unpacks values of resulting object tree. This value will not be <c>null</c>.</param>
 /// <param name="collection">Collection that the items to be stored. This value will not be <c>null</c>.</param>
 /// <exception cref="SerializationException">
 ///		Failed to deserialize object due to invalid unpacker state, stream content, or so.
 /// </exception>
 /// <exception cref="NotSupportedException">
 ///		<typeparamref name="T"/> is not collection.
 /// </exception>
 protected internal sealed override void UnpackToCore(Unpacker unpacker, object collection)
 {
     this._underlying.UnpackTo(unpacker, collection);
 }
 /// <summary>
 ///		Deserialize object with specified <see cref="Unpacker"/>.
 /// </summary>
 /// <param name="unpacker"><see cref="Unpacker"/> which unpacks values of resulting object tree. This value will not be <c>null</c>.</param>
 /// <returns>Deserialized object.</returns>
 protected internal sealed override object UnpackFromCore(Unpacker unpacker)
 {
     return(this._underlying.UnpackFrom(unpacker));
 }
 /// <summary>
 ///		Deserialize collection items with specified <see cref="Unpacker"/> and stores them to <paramref name="collection"/>.
 /// </summary>
 /// <param name="unpacker"><see cref="Unpacker"/> which unpacks values of resulting object tree. This value will not be <c>null</c>.</param>
 /// <param name="collection">Collection that the items to be stored. This value will not be <c>null</c>.</param>
 /// <exception cref="SerializationException">
 ///		Failed to deserialize object due to invalid unpacker state, stream content, or so.
 /// </exception>
 /// <exception cref="NotSupportedException">
 ///		<typeparamref name="T"/> is not collection.
 /// </exception>
 protected internal virtual void UnpackToCore(Unpacker unpacker, T collection)
 {
     throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, "This operation is not supported by '{0}'.", this.GetType()));
 }
		internal abstract object InternalUnpackFrom( Unpacker unpacker );
 object IMessagePackSerializer.UnpackFrom(Unpacker unpacker)
 {
     return(this.UnpackFrom(unpacker));
 }
		internal abstract Task<object> InternalUnpackFromAsync( Unpacker unpacker, CancellationToken cancellationToken );
示例#24
0
 protected override void UnpackFromMessageCore(Unpacker unpacker)
 {
     RpcMessageSerializer.ReadNext(unpacker);
     _str = (string)unpacker.LastReadData;
 }
示例#25
0
 internal abstract Task InternalUnpackToAsync(Unpacker unpacker, object collection, CancellationToken cancellationToken);
 protected internal override TCollection UnpackFromCore(Unpacker unpacker)
 private void UnpackMemberInMap(Unpacker unpacker, ref object instance, int index)
 {
     if (this._memberSetters[index] == null)
     {
         // Use null as marker because index mapping cannot be constructed in the constructor.
         this._memberSerializers[index].UnpackTo(unpacker, this._memberGetters[index](instance));
     }
     else
     {
         this._memberSetters[index](ref instance, this._memberSerializers[index].UnpackFrom(unpacker));
     }
 }
 protected internal override DateTime UnpackFromCore(Unpacker unpacker)
 {
     return(DateTime.FromBinary(unpacker.LastReadData.AsInt64()));
 }
示例#29
0
 static void AddUnpacker(Unpacker unpacker, params System.Type[] sql_types)
 {
     foreach (var sql_type in sql_types) {
         unpackers[sql_type] = unpacker;
     }
 }
示例#30
0
        protected override void PostSignatureUnpacked(Unpacker unpacker, int messageSize)
        {
            var startPosition = unpacker.Position - messageSize;

            (_dataHash, _signature) = unpacker.GetHashAndSignature(startPosition, messageSize);
        }
		/// <summary>
		///		Deserializes collection items with specified <see cref="Unpacker"/> and stores them to <paramref name="collection"/>.
		/// </summary>
		/// <param name="unpacker"><see cref="Unpacker"/> which unpacks values of resulting object tree. This value will not be <c>null</c>.</param>
		/// <param name="collection">Collection that the items to be stored. This value will not be <c>null</c>.</param>
		/// <exception cref="SerializationException">
		///		Failed to deserialize object due to invalid unpacker state, stream content, or so.
		/// </exception>
		/// <exception cref="NotSupportedException">
		///		The type of <paramref name="collection" /> is not a collection.
		/// </exception>
		protected internal virtual void UnpackToCore( Unpacker unpacker, object collection )
		{
			throw SerializationExceptions.NewUnpackToIsNotSupported( this._targetType, null );
		}
示例#32
0
 internal abstract Task <object> InternalUnpackFromAsync(Unpacker unpacker, CancellationToken cancellationToken);
示例#33
0
		/// <summary>
		///		Clears the buffers to deserialize message, which is not required to dispatch and invoke server method.
		/// </summary>
		internal override void ClearBuffers()
		{
			if ( this.ArgumentsBufferUnpacker != null )
			{
				this.ArgumentsBufferUnpacker.Dispose();
				this.ArgumentsBufferUnpacker = null;
			}

			if ( this.ArgumentsBufferPacker != null )
			{
				this.ArgumentsBufferPacker.Dispose();
				this.ArgumentsBufferPacker = null;
			}

			this.ArgumentsCount = 0;
			this.UnpackedArgumentsCount = 0;
			base.ClearBuffers();
		}
示例#34
0
		public static async Task< Int32> UnpackInt32ValueAsync( Unpacker unpacker, Type objectType, String memberName, CancellationToken cancellationToken )
		{
			if ( unpacker == null )
			{
				SerializationExceptions.ThrowArgumentNullException( "unpacker" );
			}

			if ( objectType == null )
			{
				SerializationExceptions.ThrowArgumentNullException( "objectType" );
			}

			if ( memberName == null )
			{
				SerializationExceptions.ThrowArgumentNullException( "memberName" );
			}

#if ASSERT
			Contract.Assert( unpacker != null );
			Contract.Assert( objectType != null );
			Contract.Assert( memberName != null );
#endif // ASSERT

			// ReSharper disable once RedundantAssignment
			var ctx = default( UnpackerTraceContext );
			InitializeUnpackerTrace( unpacker, ref ctx );

			try
			{
				AsyncReadResult<Int32> result =
					await unpacker.ReadInt32Async( cancellationToken ).ConfigureAwait( false );
				if ( !result.Success )
				{
					SerializationExceptions.ThrowFailedToDeserializeMember( objectType, memberName, null );
				}

				Trace( ctx, "ReadDirect", unpacker, memberName );

				return result.Value;
			}
			catch ( MessageTypeException ex )
			{
				SerializationExceptions.ThrowFailedToDeserializeMember( objectType, memberName, ex );
				return default( Int32 ); // never reaches.
			}
		}
示例#35
0
        public static void UnpackMapTo(Unpacker unpacker, IDictionary dictionary)
        {
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }

            if (dictionary == null)
            {
                throw new ArgumentNullException("dictionary");
            }

            if (!unpacker.IsMapHeader)
            {
                throw SerializationExceptions.NewIsNotMapHeader();
            }

#if !UNITY
            Contract.EndContractBlock();
#endif // !UNITY

            int count = GetItemsCount(unpacker);
            for (int i = 0; i < count; i++)
            {
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }

                MessagePackObject key;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    key = _messagePackObjectSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        key = _messagePackObjectSerializer.UnpackFrom(subtreeUnpacker);
                    }
                }


                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }

                MessagePackObject value;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    value = _messagePackObjectSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        value = _messagePackObjectSerializer.UnpackFrom(subtreeUnpacker);
                    }
                }

                dictionary.Add(key, value);
            }
        }
        protected internal override char[] UnpackFromCore(Unpacker unpacker)
        {
            var result = unpacker.LastReadData;

            return(result.IsNil ? null : result.AsCharArray());
        }
示例#37
0
        private T UnpackMemberValue(T objectGraph, Unpacker unpacker, int itemsCount, ref int unpacked, int index, int unpackerOffset)
        {
            object nullable = null;
            var    setter   = this._setters[index];

            if (unpacked < itemsCount)
            {
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(unpackerOffset);
                }

                if (!unpacker.LastReadData.IsNil)
                {
                    if (setter != null)
                    {
                        if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                        {
                            nullable = this._serializers[index].UnpackFrom(unpacker);
                        }
                        else
                        {
                            using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                            {
                                nullable = this._serializers[index].UnpackFrom(subtreeUnpacker);
                            }
                        }
                    }
                    else if (this._getters[index] != null)                         // null getter supposes undeclared member (should be treated as nil)
                    {
                        var collection = this._getters[index](objectGraph);
                        if (collection == null)
                        {
                            throw SerializationExceptions.NewReadOnlyMemberItemsMustNotBeNull(this._contracts[index].Name);
                        }
                        using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                        {
                            this._serializers[index].UnpackTo(subtreeUnpacker, collection);
                        }
                    }
                }
            }

            if (setter != null)
            {
                if (nullable == null)
                {
                    ReflectionNilImplicationHandler.Instance.OnUnpacked(
                        new ReflectionSerializerNilImplicationHandlerOnUnpackedParameter(
                            this._memberInfos[index].GetMemberValueType(),
                            value => SetMemverValue(objectGraph, setter, value),
                            this._contracts[index].Name,
                            this._memberInfos[index].DeclaringType
                            ),
                        this._contracts[index].NilImplication
                        )(null);
                }
                else
                {
                    objectGraph = SetMemverValue(objectGraph, setter, nullable);
                }
            }

            unpacked++;

            return(objectGraph);
        }
示例#38
0
 public RevokeablePublicServiceAccountKey(long accountId, int chainId, Unpacker unpacker) : base(unpacker)
 {
     Item = new PublicServiceAccountKey(accountId, chainId, unpacker);
 }
		/// <summary>
		///		Deserialize object with specified <see cref="Unpacker" />.
		/// </summary>
		/// <param name="unpacker"><see cref="Unpacker" /> which unpacks values of resulting object tree.</param>
		/// <returns>
		///		The deserialized object.
		/// </returns>
		/// <seealso cref="Capabilities" />
		public object UnpackFrom( Unpacker unpacker )
		{
			return this.InternalUnpackFrom( unpacker );
		}
示例#40
0
 public void Create()
 {
     unpacker = new Unpacker();
     unpacker.Prepare("0123456     Hello! \n World");
 }
		/// <summary>
		///		Deserialize collection items with specified <see cref="Unpacker" /> and stores them to <paramref name="collection" />.
		/// </summary>
		/// <param name="unpacker"><see cref="Unpacker" /> which unpacks values of resulting object tree.</param>
		/// <param name="collection">Collection that the items to be stored.</param>
		/// <seealso cref="Capabilities" />
		public void UnpackTo( Unpacker unpacker, object collection )
		{
			this.InternalUnpackTo( unpacker, collection );
		}
        protected internal override async Task <Matrix4x4> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix4x4), 16);
            }

            var length = unpacker.LastReadData.AsInt64();

            if (length != 16)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix4x4), 16);
            }


            var m11 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m11.Success)
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }


            var m12 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m12.Success)
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }


            var m13 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m13.Success)
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }


            var m14 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m14.Success)
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }


            var m21 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m21.Success)
            {
                SerializationExceptions.ThrowMissingItem(4, unpacker);
            }


            var m22 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m22.Success)
            {
                SerializationExceptions.ThrowMissingItem(5, unpacker);
            }


            var m23 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m23.Success)
            {
                SerializationExceptions.ThrowMissingItem(6, unpacker);
            }


            var m24 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m24.Success)
            {
                SerializationExceptions.ThrowMissingItem(7, unpacker);
            }


            var m31 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m31.Success)
            {
                SerializationExceptions.ThrowMissingItem(8, unpacker);
            }


            var m32 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m32.Success)
            {
                SerializationExceptions.ThrowMissingItem(9, unpacker);
            }


            var m33 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m33.Success)
            {
                SerializationExceptions.ThrowMissingItem(10, unpacker);
            }


            var m34 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m34.Success)
            {
                SerializationExceptions.ThrowMissingItem(11, unpacker);
            }


            var m41 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m41.Success)
            {
                SerializationExceptions.ThrowMissingItem(12, unpacker);
            }


            var m42 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m42.Success)
            {
                SerializationExceptions.ThrowMissingItem(13, unpacker);
            }


            var m43 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m43.Success)
            {
                SerializationExceptions.ThrowMissingItem(14, unpacker);
            }


            var m44 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m44.Success)
            {
                SerializationExceptions.ThrowMissingItem(15, unpacker);
            }



            return(new Matrix4x4(m11.Value, m12.Value, m13.Value, m14.Value, m21.Value, m22.Value, m23.Value, m24.Value, m31.Value, m32.Value, m33.Value, m34.Value, m41.Value, m42.Value, m43.Value, m44.Value));
        }
		/// <summary>
		///		Deserialize object with specified <see cref="Unpacker"/> asynchronously.
		/// </summary>
		/// <param name="unpacker"><see cref="Unpacker"/> which unpacks values of resulting object tree.</param>
		/// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
		/// <returns>
		///		A <see cref="Task"/> that represents the asynchronous operation. 
		///		The value of the <c>TResult</c> parameter contains the deserialized object.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		///		<paramref name="unpacker"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.Runtime.Serialization.SerializationException">
		///		Failed to deserialize object.
		/// </exception>
		/// <exception cref="MessageTypeException">
		///		Failed to deserialize object due to invalid stream.
		/// </exception>
		/// <exception cref="InvalidMessagePackStreamException">
		///		Failed to deserialize object due to invalid stream.
		/// </exception>
		/// <exception cref="NotSupportedException">
		///		The type of deserializing is not serializable even if it can be serialized.
		/// </exception>
		/// <seealso cref="Capabilities"/>
		public Task<object> UnpackFromAsync( Unpacker unpacker, CancellationToken cancellationToken )
		{
			return this.InternalUnpackFromAsync( unpacker, cancellationToken );
		}
示例#44
0
		public static byte[] UnpackBinaryValue( Unpacker unpacker, Type objectType, String memberName )
		{
			try
			{
				byte[] result;
				if ( !unpacker.ReadBinary( out result ) )
				{
					throw SerializationExceptions.NewFailedToDeserializeMember( objectType, memberName, null );
				}

				return result;
			}
			catch ( MessageTypeException ex )
			{
				throw SerializationExceptions.NewFailedToDeserializeMember( objectType, memberName, ex );
			}
		}
		/// <summary>
		///		Deserialize collection items with specified <see cref="Unpacker"/> and stores them to <paramref name="collection"/> asynchronously.
		/// </summary>
		/// <param name="unpacker"><see cref="Unpacker"/> which unpacks values of resulting object tree.</param>
		/// <param name="collection">Collection that the items to be stored.</param>
		/// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
		/// <returns>
		///		A <see cref="Task"/> that represents the asynchronous operation. 
		/// </returns>
		/// <exception cref="ArgumentNullException">
		///		<paramref name="unpacker"/> is <c>null</c>.
		///		Or <paramref name="collection"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="ArgumentException">
		///		<paramref name="collection"/> is not compatible for this serializer.
		/// </exception>
		/// <exception cref="System.Runtime.Serialization.SerializationException">
		///		Failed to deserialize object.
		/// </exception>
		/// <exception cref="MessageTypeException">
		///		Failed to deserialize object due to invalid stream.
		/// </exception>
		/// <exception cref="InvalidMessagePackStreamException">
		///		Failed to deserialize object due to invalid stream.
		/// </exception>
		/// <exception cref="NotSupportedException">
		///		The type of deserializing is not mutable collection.
		/// </exception>
		/// <seealso cref="Capabilities"/>
		public Task UnpackToAsync( Unpacker unpacker, object collection, CancellationToken cancellationToken )
		{
			return this.InternalUnpackToAsync( unpacker, collection, cancellationToken );
		}
        protected internal override object UnpackFromCore(Unpacker unpacker)
        {
            // Assume subtree unpacker
            var instance = this._createInstance();

            if (this._unpackFromMessage != null)
            {
                this._unpackFromMessage(ref instance, unpacker);
            }
            else
            {
                if (unpacker.IsArrayHeader)
                {
                    this.UnpackFromArray(unpacker, ref instance);
                }
                else
                {
                    this.UnpackFromMap(unpacker, ref instance);
                }
            }

            return instance;
        }
        protected internal override Matrix3x2 UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6);
            }

            var length = UnpackHelpers.GetItemsCount(unpacker);

            if (length != 6)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6);
            }


            float m11;

            if (!unpacker.ReadSingle(out m11))
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }


            float m12;

            if (!unpacker.ReadSingle(out m12))
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }


            float m21;

            if (!unpacker.ReadSingle(out m21))
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }


            float m22;

            if (!unpacker.ReadSingle(out m22))
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }


            float m31;

            if (!unpacker.ReadSingle(out m31))
            {
                SerializationExceptions.ThrowMissingItem(4, unpacker);
            }


            float m32;

            if (!unpacker.ReadSingle(out m32))
            {
                SerializationExceptions.ThrowMissingItem(5, unpacker);
            }



            return(new Matrix3x2(m11, m12, m21, m22, m31, m32));
        }
示例#48
0
 /// <summary>
 ///		Deserialize collection items with specified <see cref="Unpacker"/> and stores them to <paramref name="collection"/> asynchronously.
 /// </summary>
 /// <param name="unpacker"><see cref="Unpacker"/> which unpacks values of resulting object tree.</param>
 /// <param name="collection">Collection that the items to be stored.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
 /// <returns>
 ///		A <see cref="Task"/> that represents the asynchronous operation.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 ///		<paramref name="unpacker"/> is <c>null</c>.
 ///		Or <paramref name="collection"/> is <c>null</c>.
 /// </exception>
 /// <exception cref="ArgumentException">
 ///		<paramref name="collection"/> is not compatible for this serializer.
 /// </exception>
 /// <exception cref="System.Runtime.Serialization.SerializationException">
 ///		Failed to deserialize object.
 /// </exception>
 /// <exception cref="MessageTypeException">
 ///		Failed to deserialize object due to invalid stream.
 /// </exception>
 /// <exception cref="InvalidMessagePackStreamException">
 ///		Failed to deserialize object due to invalid stream.
 /// </exception>
 /// <exception cref="NotSupportedException">
 ///		The type of deserializing is not mutable collection.
 /// </exception>
 /// <seealso cref="Capabilities"/>
 public Task UnpackToAsync(Unpacker unpacker, object collection, CancellationToken cancellationToken)
 {
     return(this.InternalUnpackToAsync(unpacker, collection, cancellationToken));
 }
 protected internal override void UnpackToCore(Unpacker unpacker, object collection)
 {
     this._unpackToCore(unpacker, collection, this._elementSerializer);
 }
        protected internal override async Task <Matrix3x2> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6);
            }

            var length = unpacker.LastReadData.AsInt64();

            if (length != 6)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6);
            }


            var m11 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m11.Success)
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }


            var m12 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m12.Success)
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }


            var m21 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m21.Success)
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }


            var m22 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m22.Success)
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }


            var m31 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m31.Success)
            {
                SerializationExceptions.ThrowMissingItem(4, unpacker);
            }


            var m32 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m32.Success)
            {
                SerializationExceptions.ThrowMissingItem(5, unpacker);
            }



            return(new Matrix3x2(m11.Value, m12.Value, m21.Value, m22.Value, m31.Value, m32.Value));
        }
        private void UnpackFromArray(Unpacker unpacker, ref object instance)
        {
            int unpacked = 0;
            int itemsCount = checked((int)unpacker.ItemsCount);
            for (int i = 0; i < this.MemberSerializers.Length; i++)
            {
                if (unpacked == itemsCount)
                {
                    // It is OK to avoid skip missing member because default NilImplication is MemberDefault so it is harmless.
                    this.HandleNilImplication(ref instance, i);
                }
                else
                {
                    if (!unpacker.Read())
                    {
                        throw SerializationExceptions.NewUnexpectedEndOfStream();
                    }

                    if (unpacker.LastReadData.IsNil)
                    {
                        this.HandleNilImplication(ref instance, i);
                    }
                    else
                    {
                        if (unpacker.IsArrayHeader || unpacker.IsMapHeader)
                        {
                            using (var subtreeUnpacker = unpacker.ReadSubtree())
                            {
                                this.UnpackMemberInArray(subtreeUnpacker, ref instance, i);
                            }
                        }
                        else
                        {
                            this.UnpackMemberInArray(unpacker, ref instance, i);
                        }
                    }

                    unpacked++;
                }
            }
        }
        protected internal override Matrix4x4 UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix4x4), 16);
            }

            var length = UnpackHelpers.GetItemsCount(unpacker);

            if (length != 16)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix4x4), 16);
            }


            float m11;

            if (!unpacker.ReadSingle(out m11))
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }


            float m12;

            if (!unpacker.ReadSingle(out m12))
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }


            float m13;

            if (!unpacker.ReadSingle(out m13))
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }


            float m14;

            if (!unpacker.ReadSingle(out m14))
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }


            float m21;

            if (!unpacker.ReadSingle(out m21))
            {
                SerializationExceptions.ThrowMissingItem(4, unpacker);
            }


            float m22;

            if (!unpacker.ReadSingle(out m22))
            {
                SerializationExceptions.ThrowMissingItem(5, unpacker);
            }


            float m23;

            if (!unpacker.ReadSingle(out m23))
            {
                SerializationExceptions.ThrowMissingItem(6, unpacker);
            }


            float m24;

            if (!unpacker.ReadSingle(out m24))
            {
                SerializationExceptions.ThrowMissingItem(7, unpacker);
            }


            float m31;

            if (!unpacker.ReadSingle(out m31))
            {
                SerializationExceptions.ThrowMissingItem(8, unpacker);
            }


            float m32;

            if (!unpacker.ReadSingle(out m32))
            {
                SerializationExceptions.ThrowMissingItem(9, unpacker);
            }


            float m33;

            if (!unpacker.ReadSingle(out m33))
            {
                SerializationExceptions.ThrowMissingItem(10, unpacker);
            }


            float m34;

            if (!unpacker.ReadSingle(out m34))
            {
                SerializationExceptions.ThrowMissingItem(11, unpacker);
            }


            float m41;

            if (!unpacker.ReadSingle(out m41))
            {
                SerializationExceptions.ThrowMissingItem(12, unpacker);
            }


            float m42;

            if (!unpacker.ReadSingle(out m42))
            {
                SerializationExceptions.ThrowMissingItem(13, unpacker);
            }


            float m43;

            if (!unpacker.ReadSingle(out m43))
            {
                SerializationExceptions.ThrowMissingItem(14, unpacker);
            }


            float m44;

            if (!unpacker.ReadSingle(out m44))
            {
                SerializationExceptions.ThrowMissingItem(15, unpacker);
            }



            return(new Matrix4x4(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44));
        }
 private static string GetMemberName(Unpacker unpacker)
 {
     try
     {
         return unpacker.LastReadData.AsString();
     }
     catch (InvalidOperationException ex)
     {
         throw new InvalidMessagePackStreamException("Cannot get a member name from stream.", ex);
     }
 }
 protected internal override DateTime UnpackFromCore(Unpacker unpacker)
 {
     return(MessagePackConvert.ToDateTime(unpacker.LastReadData.AsInt64()));
 }
            public object UnpackFrom(Unpacker unpacker)
            {
                if (unpacker == null)
                {
                    throw new ArgumentNullException("unpacker");
                }

                Contract.Ensures(Contract.Result<object>() == null);

                // Always returns null.
                return null;
            }
示例#56
0
 protected internal override void UnpackToCore(Unpacker unpacker, T[] collection)
示例#57
0
		internal virtual void ClearBuffers()
		{
			if ( this.HeaderUnpacker != null )
			{
				try
				{
					this.HeaderUnpacker.Dispose();
				}
				catch ( InvalidMessagePackStreamException )
				{
					// Handles cleanup for corruppted stream.
				}

				this.HeaderUnpacker = null;
			}

			if ( this.RootUnpacker != null )
			{
				try
				{
					this.RootUnpacker.Dispose();
				}
				catch ( InvalidMessagePackStreamException )
				{
					// Handles cleanup for corruppted stream.
				}

				this.RootUnpacker = null;
			}

			if ( this.UnpackingBuffer != null )
			{
				this.TruncateUsedReceivedData();
			}
		}
示例#58
0
 private void UnpackToCore(Unpacker unpacker, T[] collection, int count)
示例#59
0
 private static Retriever Bind(string name, int position, Unpacker unpacker)
 {
     return (rs, frame) => frame.Set(name, rs.IsDBNull(position) ? Unit.NULL : unpacker(rs, position));
 }
示例#60
0
 protected internal override T[] UnpackFromCore(Unpacker unpacker)