• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Unpacker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Unpacker的典型用法代码示例。如果您正苦于以下问题:C# Unpacker类的具体用法?C# Unpacker怎么用?C# Unpacker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Unpacker类属于命名空间,在下文中一共展示了Unpacker类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: UnpackDictionary

 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;
 }
开发者ID:Keith-Redding,项目名称:msgpack,代码行数:10,代码来源:TestFileReading.cs


示例2: UnpackFromCore

        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;
        }
开发者ID:songotony,项目名称:RType-Client,代码行数:11,代码来源:ArrayRecflectionMessagePackSerializer.cs


示例3: UnpackNullableBooleanValue

		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 );
			}
		}
开发者ID:nagyist,项目名称:msgpack-cli,代码行数:17,代码来源:UnpackHelpers.direct.cs


示例4: UnpackBooleanValue

		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.
			}
		}
开发者ID:msgpack,项目名称:msgpack-cli,代码行数:45,代码来源:UnpackHelpers.direct.cs


示例5: TestReadFromFile

        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));
            }
        }
开发者ID:Keith-Redding,项目名称:msgpack,代码行数:38,代码来源:TestFileReading.cs


示例6: UnpackFrom

		/// <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 );
		}
开发者ID:msgpack,项目名称:msgpack-cli,代码行数:12,代码来源:MessagePackSerializer.cs


示例7: InternalUnpackToAsync

		internal abstract Task InternalUnpackToAsync( Unpacker unpacker, object collection, CancellationToken cancellationToken );
开发者ID:msgpack,项目名称:msgpack-cli,代码行数:1,代码来源:MessagePackSerializer.cs


示例8: UnpackToCore

		/// <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 );
		}
开发者ID:msgpack,项目名称:msgpack-cli,代码行数:15,代码来源:NonGenericMessagePackSerializer.cs


示例9: AddUnpacker

 static void AddUnpacker(Unpacker unpacker, params System.Type[] sql_types)
 {
     foreach (var sql_type in sql_types) {
         unpackers[sql_type] = unpacker;
     }
 }
开发者ID:davidhankins,项目名称:flabbergast,代码行数:6,代码来源:sql.cs


示例10: UnpackTo

            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()));
            }
开发者ID:songotony,项目名称:RType-Client,代码行数:14,代码来源:ObjectReflectionMessagePackSerializer.cs


示例11: UnpackMemberInMap

 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));
     }
 }
开发者ID:songotony,项目名称:RType-Client,代码行数:12,代码来源:ObjectReflectionMessagePackSerializer.cs


示例12: UnpackFromMap

        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);
                }
            }
        }
开发者ID:songotony,项目名称:RType-Client,代码行数:58,代码来源:ObjectReflectionMessagePackSerializer.cs


示例13: UnpackFromCore

        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;
        }
开发者ID:songotony,项目名称:RType-Client,代码行数:23,代码来源:ObjectReflectionMessagePackSerializer.cs


示例14: UnpackBinaryValue

		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 );
			}
		}
开发者ID:nagyist,项目名称:msgpack-cli,代码行数:17,代码来源:UnpackHelpers.direct.cs


示例15: UnpackInt32ValueAsync

		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.
			}
		}
开发者ID:msgpack,项目名称:msgpack-cli,代码行数:46,代码来源:UnpackHelpers.direct.cs


示例16: UnpackFromCore

 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;
 }
开发者ID:songotony,项目名称:RType-Client,代码行数:6,代码来源:MapReflectionMessagePackSerializer.cs


示例17: ClearDispatchContext

		/// <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();
		}
开发者ID:Indifer,项目名称:Test,代码行数:16,代码来源:ServerRequestContext.cs


示例18: ClearBuffers

		/// <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();
		}
开发者ID:Indifer,项目名称:Test,代码行数:21,代码来源:ServerRequestContext.cs


示例19: UnpackToCore

 protected internal override void UnpackToCore(Unpacker unpacker, object collection)
 {
     this._unpackToCore(unpacker, collection, this._elementSerializer);
 }
开发者ID:songotony,项目名称:RType-Client,代码行数:4,代码来源:SequenceReflectionMessagePackSerializer.cs


示例20: InternalUnpackFrom

		internal abstract object InternalUnpackFrom( Unpacker unpacker );
开发者ID:msgpack,项目名称:msgpack-cli,代码行数:1,代码来源:MessagePackSerializer.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UnrealTargetConfiguration类代码示例发布时间:2022-05-24
下一篇:
C# UnpackedRecord类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap