當前位置: 首頁>>代碼示例>>C#>>正文


C# MsgPack.SplittingStream類代碼示例

本文整理匯總了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() );
			}
		}
開發者ID:gezidan,項目名稱:ZYSOCKET,代碼行數:26,代碼來源:UnpackerTest.Raw.cs

示例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 ) );
			}
		}
開發者ID:msgpack,項目名稱:msgpack-cli,代碼行數:14,代碼來源:UnpackerTest.Scalar.cs

示例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() );
				}
			}
		}
開發者ID:gezidan,項目名稱:ZYSOCKET,代碼行數:15,代碼來源:PackUnpackTest.Scalar.cs

示例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 ) );
			}
		}
開發者ID:msgpack,項目名稱:msgpack-cli,代碼行數:23,代碼來源:UnpackerTest.Ext.cs

示例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 ) );
			}
		}
開發者ID:gezidan,項目名稱:ZYSOCKET,代碼行數:15,代碼來源:UnpackerTest.Raw.cs

示例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() );
			}
		}
開發者ID:gezidan,項目名稱:ZYSOCKET,代碼行數:14,代碼來源:UnpackerTest.Raw.cs

示例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() );
			}
		}
開發者ID:gezidan,項目名稱:ZYSOCKET,代碼行數:14,代碼來源:UnpackerTest.Raw.cs

示例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 ) );
			}
		}
開發者ID:gezidan,項目名稱:ZYSOCKET,代碼行數:15,代碼來源:UnpackerTest.Raw.cs

示例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() );
			}
		}
開發者ID:gezidan,項目名稱:ZYSOCKET,代碼行數:24,代碼來源:UnpackerTest.Raw.cs

示例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 ) );
			}
		}
開發者ID:msgpack,項目名稱:msgpack-cli,代碼行數:13,代碼來源:UnpackerTest.Scalar.cs

示例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 ) );
			}
		}
開發者ID:msgpack,項目名稱:msgpack-cli,代碼行數:13,代碼來源:UnpackerTest.Scalar.cs

示例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 ) );
			}
		}
開發者ID:msgpack,項目名稱:msgpack-cli,代碼行數:13,代碼來源:UnpackerTest.Scalar.cs

示例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 ) );
			}
		}
開發者ID:msgpack,項目名稱:msgpack-cli,代碼行數:13,代碼來源:UnpackerTest.Scalar.cs

示例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 ) );
			}
		}
開發者ID:msgpack,項目名稱:msgpack-cli,代碼行數:14,代碼來源:UnpackerTest.Scalar.cs

示例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 ) );
			}
		}
開發者ID:msgpack,項目名稱:msgpack-cli,代碼行數:13,代碼來源:UnpackerTest.Scalar.cs


注:本文中的MsgPack.SplittingStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。