本文整理汇总了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();
}
示例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();
}
}
示例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
{
//.........这里部分代码省略.........