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


C# MessagePackObject.AsList方法代码示例

本文整理汇总了C#中MessagePackObject.AsList方法的典型用法代码示例。如果您正苦于以下问题:C# MessagePackObject.AsList方法的具体用法?C# MessagePackObject.AsList怎么用?C# MessagePackObject.AsList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MessagePackObject的用法示例。


在下文中一共展示了MessagePackObject.AsList方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UnpackFromMessage

		public void UnpackFromMessage( MessagePackObject messagePackObject )
		{
		
			if (! messagePackObject.IsTypeOf<IList<MessagePackObject>>().GetValueOrDefault() )
			{
				throw new ArgumentException(messagePackObject.UnderlyingType.ToString());
			}

			var asList = messagePackObject.AsList();
			if ( asList.Count != 5 )
			{
				throw new ArgumentException();
			}

			uri = asList[ 0 ].AsString();
			title = asList[ 1].AsString();
			width = asList[ 2 ].AsInt32();
			height = asList[ 3 ].AsInt32();
			size = asList[ 4 ].AsInt32();
		}
开发者ID:davemkirk,项目名称:msgpack-cli,代码行数:20,代码来源:Image.cs

示例2: Dump

		private static void Dump( MessagePackObject obj, StringBuilder buffer, int indent )
		{
			if ( obj.IsNil )
			{
				buffer.Append( ' ', indent * 2 ).Append( "(null)" ).AppendLine();
			}
			else if ( obj.IsTypeOf<IList<MessagePackObject>>().GetValueOrDefault() )
			{
				buffer.Append( ' ', indent * 2 ).AppendLine( "(" );

				foreach ( var child in obj.AsList() )
				{
					Dump( child, buffer, indent + 1 );
				}

				buffer.Append( ' ', indent * 2 ).AppendLine( ")" );
			}
			else if ( obj.IsTypeOf<IDictionary<MessagePackObject, MessagePackObject>>().GetValueOrDefault() )
			{
				buffer.Append( ' ', indent * 2 ).AppendLine( "{" );

				foreach ( var child in obj.AsDictionary() )
				{
					Dump( child.Key, buffer, indent + 1 );
					buffer.Append( ' ', ( indent + 1 ) * 2 ).AppendLine( "= " );
					Dump( child.Value, buffer, indent + 2 );
				}

				buffer.Append( ' ', indent * 2 ).AppendLine( "}" );
			}
			else
			{
				buffer.Append( ' ', indent * 2 ).Append( obj ).Append( " : " ).Append( obj.UnderlyingType ).AppendLine();
			}
		}
开发者ID:eslo,项目名称:msgpack-cli,代码行数:35,代码来源:PackUnpackTest.cs

示例3: TestDeserializeDeviedCore

		private static void TestDeserializeDeviedCore( int id, object returnValue, bool isVoid, RpcException error )
		{
			if ( isVoid )
			{
				Assert.IsNull( returnValue, "Return value should not be specified in void." );
			}

			if ( error != null )
			{
				Assert.IsNull( returnValue, "Return value shoud not be specified in error." );
				Assert.IsFalse( isVoid, "isVoid should be false in error test." );
			}
			// TODO: Mock filters
			var objectTracingFilter = new DeserializedResponseTracingFilterProvider();
			var binaryTracingFilter = new DeserializingResponseTracingFilterProvider();
			var target =
				SerializerFactory.CreateResponseMessageSerializerWithTracer(
					null,
					null,
					binaryTracingFilter,
					objectTracingFilter
				);
			try
			{
				var expected =
					new MessagePackObject(
						new MessagePackObject[]
					{
						new MessagePackObject( ( int )MessageType.Response ),
						new MessagePackObject( ( uint )id ),
						error == null ? MessagePackObject.Nil : error.RpcError.Identifier,
						returnValue == null 
							? ( error == null ? MessagePackObject.Nil : error.GetExceptionMessage( false ) )
							: MessagePackObject.FromObject( returnValue )						
					}
					);
				var stream = new MemoryStream();
				Packer.Create( stream ).Pack( expected );
				var serialized = stream.ToArray();
				var packets = Segmentate( serialized, 10 ).ToArray();
				int indexOfPackets = 0;
				using ( var underlying = ChunkBuffer.CreateDefault() )
				{
					underlying.Feed( new ArraySegment<byte>( packets[ 0 ] ) );
					using ( var buffer =
						new RpcInputBuffer<object, object>(
							underlying,
							( _0, _1, _2 ) => ChunkBuffer.CreateDefault(),
							( item, _0, _1 ) =>
							{
								indexOfPackets++;
								if ( indexOfPackets >= packets.Length )
								{
									return default( BufferFeeding );
									//Assert.Fail( "Over requesting." );
								}

								item.Reset();
								item.Feed( new ArraySegment<byte>( packets[ indexOfPackets ] ) );
								return new BufferFeeding( packets[ indexOfPackets ].Length );
							},
							null
						) )
					{
						ResponseMessage actual;
						var result = target.Deserialize( buffer, out actual );
						Assert.IsTrue( result.IsSuccess, result.ToString() );
						Assert.AreEqual( id, actual.MessageId );
						if ( isVoid || returnValue == null )
						{
							Assert.IsTrue( actual.ReturnValue.IsNil );
						}
						else
						{
							Assert.AreEqual( returnValue.ToString(), actual.ReturnValue.AsString() );
						}

						if ( error == null )
						{
							Assert.IsNull( actual.Error );
						}
						else
						{
							Assert.AreEqual( expected.AsList()[ 2 ].AsString(), actual.Error.RpcError.Identifier );
							Assert.AreEqual( expected.AsList()[ 3 ].AsDictionary()[ MessagePackConvert.EncodeString( "ErrorCode" ) ].AsInt32(), actual.Error.RpcError.ErrorCode );
							Assert.AreEqual( expected.AsList()[ 3 ].AsDictionary()[ MessagePackConvert.EncodeString( "Message" ) ].AsString(), actual.Error.Message );
							if ( expected.AsList()[ 3 ].AsDictionary().ContainsKey( MessagePackConvert.EncodeString( "DebugInformation" ) ) )
							{
								Assert.AreEqual( expected.AsList()[ 3 ].AsDictionary()[ MessagePackConvert.EncodeString( "DebugInformation" ) ].AsString(), actual.Error.DebugInformation );
							}
							else
							{
								Assert.IsNull( actual.Error.DebugInformation );
							}
						}
					}
				}
			}
			finally
			{
//.........这里部分代码省略.........
开发者ID:yfakariya,项目名称:msgpack-rpc,代码行数:101,代码来源:ResponseMessageSerializerTest.cs


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