本文整理汇总了C#中MessagePackObject.AsInt32方法的典型用法代码示例。如果您正苦于以下问题:C# MessagePackObject.AsInt32方法的具体用法?C# MessagePackObject.AsInt32怎么用?C# MessagePackObject.AsInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessagePackObject
的用法示例。
在下文中一共展示了MessagePackObject.AsInt32方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnpackError
/// <summary>
/// Unpacks <see cref="RpcErrorMessage"/> from stream in the specified context.
/// </summary>
/// <param name="context"><see cref="ClientResponseContext"/> which stores serialized error.</param>
/// <returns>An unpacked <see cref="RpcErrorMessage"/>.</returns>
internal static RpcErrorMessage UnpackError( ClientResponseContext context )
{
Contract.Assert( context != null );
Contract.Assert( context.ErrorBuffer != null );
Contract.Assert( context.ErrorBuffer.Length > 0 );
Contract.Assert( context.ResultBuffer != null );
Contract.Assert( context.ResultBuffer.Length > 0 );
MessagePackObject error;
try
{
error = Unpacking.UnpackObject( context.ErrorBuffer );
}
catch ( UnpackException )
{
error = new MessagePackObject( context.ErrorBuffer.GetBuffer().SelectMany( segment => segment.AsEnumerable() ).ToArray() );
}
if ( error.IsNil )
{
return RpcErrorMessage.Success;
}
bool isUnknown = false;
RpcError errorIdentifier;
if ( error.IsTypeOf<string>().GetValueOrDefault() )
{
var asString = error.AsString();
errorIdentifier = RpcError.FromIdentifier( asString, null );
// Check if the error is truely Unexpected error.
isUnknown = errorIdentifier.ErrorCode == RpcError.Unexpected.ErrorCode && asString != RpcError.Unexpected.Identifier;
}
else if ( error.IsTypeOf<int>().GetValueOrDefault() )
{
errorIdentifier = RpcError.FromIdentifier( null, error.AsInt32() );
}
else
{
errorIdentifier = RpcError.Unexpected;
isUnknown = true;
}
MessagePackObject detail;
if ( context.ResultBuffer.Length == 0 )
{
detail = MessagePackObject.Nil;
}
else
{
try
{
detail = Unpacking.UnpackObject( context.ResultBuffer );
}
catch ( UnpackException )
{
detail = new MessagePackObject( context.ResultBuffer.GetBuffer().SelectMany( segment => segment.AsEnumerable() ).ToArray() );
}
}
if ( isUnknown )
{
// Unknown error, the error should contain original Error field as message.
if ( detail.IsNil )
{
return new RpcErrorMessage( errorIdentifier, error.AsString(), null );
}
else
{
var details = new MessagePackObjectDictionary( 2 );
details[ RpcException.MessageKeyUtf8 ] = error;
details[ RpcException.DebugInformationKeyUtf8 ] = detail;
return new RpcErrorMessage( errorIdentifier, new MessagePackObject( details, true ) );
}
}
else
{
return new RpcErrorMessage( errorIdentifier, detail );
}
}