本文整理汇总了C#中MsgPack.SplittingStream类的典型用法代码示例。如果您正苦于以下问题:C# SplittingStream类的具体用法?C# SplittingStream怎么用?C# SplittingStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SplittingStream类属于MsgPack命名空间,在下文中一共展示了SplittingStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestUnpackFixStr_0_AsString_Read_JustLength_Splitted
public void TestUnpackFixStr_0_AsString_Read_JustLength_Splitted()
{
using( var buffer =
new MemoryStream(
new byte[] { 0xA0 }
.Concat( Enumerable.Repeat( ( byte )'A', 0 ) ).ToArray()
)
)
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Assert.IsTrue( unpacker.Read() );
#pragma warning disable 612,618
var result = unpacker.Data;
#pragma warning restore 612,618
Assert.IsTrue( result.HasValue );
Assert.That( ( String )result.Value, Is.EqualTo( new String( 'A', 0 ) ) );
Assert.That( result.Value.UnderlyingType, Is.EqualTo( typeof( String ) ) );
// raw/str always can be byte[]
var asBinary = ( byte[] )result.Value;
var asString = ( String )result.Value;
Assert.That( result.Value.IsTypeOf( typeof( string ) ).GetValueOrDefault() );
Assert.That( result.Value.IsTypeOf( typeof( byte[] ) ).GetValueOrDefault() );
}
}
示例2: TestRead_Int64MinValue_Splitted
public void TestRead_Int64MinValue_Splitted()
{
using( var buffer = new MemoryStream( new byte[] { 0xD3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } ) )
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Assert.IsTrue( unpacker.Read() );
#pragma warning disable 612,618
var result = unpacker.Data;
#pragma warning restore 612,618
Assert.IsTrue( result.HasValue );
Assert.That( ( System.Int64 )result.Value, Is.EqualTo( -9223372036854775808 ) );
}
}
示例3: TestByte_Splitted
public void TestByte_Splitted()
{
var value = Byte.MaxValue;
using( var output = new MemoryStream() )
{
Packer.Create( output ).Pack( value );
output.Position = 0;
using( var splitted = new SplittingStream( output ) )
{
var mpo = Unpacking.UnpackObject( splitted );
Assert.AreEqual( value, ( Byte )mpo );
Assert.AreEqual( value, mpo.AsByte() );
}
}
}
示例4: TestRead_FixExt1_AndBinaryLengthIs1JustLength_Success_Splitted
public void TestRead_FixExt1_AndBinaryLengthIs1JustLength_Success_Splitted()
{
var typeCode = ( byte )( Math.Abs( Environment.TickCount ) % 128 );
using( var buffer =
new MemoryStream(
new byte[] { 0xD4, typeCode }
.Concat( Enumerable.Repeat( ( byte )0xFF, 1 ) ).ToArray()
)
)
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Assert.IsTrue( unpacker.Read() );
#pragma warning disable 612,618
var result = unpacker.Data;
#pragma warning restore 612,618
Assert.IsTrue( result.HasValue );
var actual = ( MessagePackExtendedTypeObject )result;
Assert.That( actual.TypeCode, Is.EqualTo( typeCode ) );
Assert.That( actual.Body, Is.Not.Null );
Assert.That( actual.Body.Length, Is.EqualTo( 1 ) );
}
}
示例5: TestUnpackBin32_65536_ReadString_TooShort_Splitted
public void TestUnpackBin32_65536_ReadString_TooShort_Splitted()
{
using( var buffer =
new MemoryStream(
new byte[] { 0xC6, 0, 1, 0, 0 }
.Concat( Enumerable.Repeat( ( byte )'A', 65535 ) ).ToArray()
)
)
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
String result;
Assert.Throws<InvalidMessagePackStreamException>( () => unpacker.ReadString( out result ) );
}
}
示例6: TestUnpackStr8_1_AsString_Read_TooShort_Splitted
public void TestUnpackStr8_1_AsString_Read_TooShort_Splitted()
{
using( var buffer =
new MemoryStream(
new byte[] { 0xD9, 1 }
.Concat( Enumerable.Repeat( ( byte )'A', 0 ) ).ToArray()
)
)
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Assert.Throws<InvalidMessagePackStreamException>( () => unpacker.Read() );
}
}
示例7: TestUnpackBin32_65535_AsBinary_Read_TooShort_Splitted
public void TestUnpackBin32_65535_AsBinary_Read_TooShort_Splitted()
{
using( var buffer =
new MemoryStream(
new byte[] { 0xC6, 0, 0, 0xFF, 0xFF }
.Concat( Enumerable.Repeat( ( byte )0xFF, 65534 ) ).ToArray()
)
)
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Assert.Throws<InvalidMessagePackStreamException>( () => unpacker.Read() );
}
}
示例8: TestUnpackBin16_256_ReadBinary_TooShort_Splitted
public void TestUnpackBin16_256_ReadBinary_TooShort_Splitted()
{
using( var buffer =
new MemoryStream(
new byte[] { 0xC5, 1, 0 }
.Concat( Enumerable.Repeat( ( byte )0xFF, 255 ) ).ToArray()
)
)
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Byte[] result;
Assert.Throws<InvalidMessagePackStreamException>( () => unpacker.ReadBinary( out result ) );
}
}
示例9: TestUnpackStr32_0_AsBinary_Read_HasExtra_Splitted
public void TestUnpackStr32_0_AsBinary_Read_HasExtra_Splitted()
{
using( var buffer =
new MemoryStream(
new byte[] { 0xDB, 0, 0, 0, 0 }
.Concat( Enumerable.Repeat( ( byte )0xFF, 1 ) ).ToArray()
)
)
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Assert.IsTrue( unpacker.Read() );
#pragma warning disable 612,618
var result = unpacker.Data;
#pragma warning restore 612,618
Assert.IsTrue( result.HasValue );
// raw/str always can be byte[]
var asBinary = ( byte[] )result.Value;
var asString = ( String )result.Value;
Assert.That( result.Value.IsTypeOf( typeof( string ) ).GetValueOrDefault() );
Assert.That( result.Value.IsTypeOf( typeof( byte[] ) ).GetValueOrDefault() );
}
}
示例10: TestReadNullableDoubleAsync_DoubleNegativeZero_Splitted
public async Task TestReadNullableDoubleAsync_DoubleNegativeZero_Splitted()
{
using( var buffer = new MemoryStream( new byte[] { 0xCB, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } ) )
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Double? result;
var ret = await unpacker.ReadNullableDoubleAsync();
Assert.IsTrue( ret.Success );
result = ret.Value;
Assert.That( ( -0.0 ).Equals( result.Value ) );
}
}
示例11: TestReadDoubleAsync_DoubleEpsilon_Splitted
public async Task TestReadDoubleAsync_DoubleEpsilon_Splitted()
{
using( var buffer = new MemoryStream( new byte[] { 0xCB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } ) )
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Double result;
var ret = await unpacker.ReadDoubleAsync();
Assert.IsTrue( ret.Success );
result = ret.Value;
Assert.That( Double.Epsilon.Equals( result ) );
}
}
示例12: TestReadNullableDoubleAsync_DoubleMaxValue_Splitted
public async Task TestReadNullableDoubleAsync_DoubleMaxValue_Splitted()
{
using( var buffer = new MemoryStream( new byte[] { 0xCB, 0x7F, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } ) )
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Double? result;
var ret = await unpacker.ReadNullableDoubleAsync();
Assert.IsTrue( ret.Success );
result = ret.Value;
Assert.That( Double.MaxValue.Equals( result.Value ) );
}
}
示例13: TestReadSingleAsync_SingleNegativeInfinity_Splitted
public async Task TestReadSingleAsync_SingleNegativeInfinity_Splitted()
{
using( var buffer = new MemoryStream( new byte[] { 0xCA, 0xFF, 0x80, 0x00, 0x00 } ) )
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Single result;
var ret = await unpacker.ReadSingleAsync();
Assert.IsTrue( ret.Success );
result = ret.Value;
Assert.That( Single.IsNegativeInfinity( result ) );
}
}
示例14: TestReadAsync_SingleNaNNegativeMaxValue_Splitted
public async Task TestReadAsync_SingleNaNNegativeMaxValue_Splitted()
{
using( var buffer = new MemoryStream( new byte[] { 0xCA, 0xFF, 0xFF, 0xFF, 0xFF } ) )
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Assert.IsTrue( await unpacker.ReadAsync() );
#pragma warning disable 612,618
var result = unpacker.Data;
#pragma warning restore 612,618
Assert.IsTrue( result.HasValue );
Assert.That( Single.IsNaN( ( System.Single )result.Value ) );
}
}
示例15: TestReadNullableSingleAsync_SingleNaNPositiveMaxValue_Splitted
public async Task TestReadNullableSingleAsync_SingleNaNPositiveMaxValue_Splitted()
{
using( var buffer = new MemoryStream( new byte[] { 0xCA, 0x7F, 0xFF, 0xFF, 0xFF } ) )
using( var splitted = new SplittingStream( buffer ) )
using( var unpacker = Unpacker.Create( splitted ) )
{
Single? result;
var ret = await unpacker.ReadNullableSingleAsync();
Assert.IsTrue( ret.Success );
result = ret.Value;
Assert.That( Single.IsNaN( result.Value ) );
}
}