本文整理汇总了C#中MessagePackObject.AsString方法的典型用法代码示例。如果您正苦于以下问题:C# MessagePackObject.AsString方法的具体用法?C# MessagePackObject.AsString怎么用?C# MessagePackObject.AsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessagePackObject
的用法示例。
在下文中一共展示了MessagePackObject.AsString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAsString1_EncodingIsNotUtf32_SpecifyUtf32_Fail
public void TestAsString1_EncodingIsNotUtf32_SpecifyUtf32_Fail()
{
#if MONO
Assert.Inconclusive( "UTF32Encoding does not throw exception on Mono FCL." );
#endif
var target = new MessagePackObject( new byte[] { 0xFF } );
Assert.Throws<InvalidOperationException>( () => target.AsString( new UTF32Encoding( bigEndian: false, byteOrderMark: false, throwOnInvalidCharacters: true ) ) );
}
示例2: TestAsString1_EncodingIsUtf32_SpecifyUtf32_Success
public void TestAsString1_EncodingIsUtf32_SpecifyUtf32_Success()
{
var target = new MessagePackObject( Encoding.UTF32.GetBytes( _japanese ) );
var result = target.AsString( Encoding.UTF32 );
Assert.AreEqual( _japanese, result );
}
示例3: TestAsString1_EncodingIsUtf32_SpecifyNotUtf32_Fail
public void TestAsString1_EncodingIsUtf32_SpecifyNotUtf32_Fail()
{
var target = new MessagePackObject( Encoding.UTF32.GetBytes( _japanese ) );
Assert.Throws<InvalidOperationException>( () => target.AsString( new UTF8Encoding( encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true ) ) );
}
示例4: TestAsString1_EncodingMissmatchAndReturnsNull_Null
public void TestAsString1_EncodingMissmatchAndReturnsNull_Null()
{
var target = new MessagePackObject( Encoding.Unicode.GetBytes( _japanese ) );
Assert.Throws<InvalidOperationException>( () => target.AsString( new UTF8Encoding( encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: false ) ) );
}
示例5: TestAsString1_EncodingIsNull
public void TestAsString1_EncodingIsNull()
{
var target = new MessagePackObject( Encoding.Unicode.GetBytes( _japanese ) );
Assert.Throws<ArgumentNullException>( () => target.AsString( null ) );
}
示例6: TestAsString_Null_Success
public void TestAsString_Null_Success()
{
var target = new MessagePackObject( default( string ) );
Assert.IsNull( target.AsString() );
}
示例7: TestAsString_IsNotString
public void TestAsString_IsNotString()
{
var target = new MessagePackObject( 0 );
Assert.Throws<InvalidOperationException>( () => target.AsString() );
}
示例8: TestAsString1_EncodingIsUtf32_SpecifyNotUtf32_Fail
public void TestAsString1_EncodingIsUtf32_SpecifyNotUtf32_Fail()
{
var target = new MessagePackObject( Encoding.UTF32.GetBytes( _japanese ) );
var result = target.AsString( new UTF8Encoding( encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true ) );
}
示例9: TestAsString_EncodingMissmatch
public void TestAsString_EncodingMissmatch()
{
var target = new MessagePackObject( Encoding.Unicode.GetBytes( _japanese ) );
Assert.Throws<InvalidOperationException>( () => target.AsString() );
}
示例10: TestAsString1_EncodingMissmatchAndThrowsDecoderFallbackException
public void TestAsString1_EncodingMissmatchAndThrowsDecoderFallbackException()
{
var target = new MessagePackObject( Encoding.Unicode.GetBytes( _japanese ) );
var result = target.AsString( new UTF8Encoding( encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true ) );
}
示例11: TestAsString1_EncodingIsNull
public void TestAsString1_EncodingIsNull()
{
var target = new MessagePackObject( Encoding.Unicode.GetBytes( _japanese ) );
var result = target.AsString( null );
}
示例12: TestAsString_IsNotString
public void TestAsString_IsNotString()
{
var target = new MessagePackObject( 0 );
target.AsString();
}
示例13: TestAsString_EncodingMissmatch
public void TestAsString_EncodingMissmatch()
{
var target = new MessagePackObject( Encoding.Unicode.GetBytes( _japanese ) );
var result = target.AsString();
}
示例14: TestAsString1_IsNotString
public void TestAsString1_IsNotString()
{
var target = new MessagePackObject( 0 );
target.AsString( Encoding.UTF32 );
}
示例15: 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 );
}
}