UnpackCharStream() public static method

Unpacks raw value from the specified Stream as UnpackingStreamReader with UTF-8 encoding.

if source contains invalid sequence as UTF-8 encoding string, the DecoderFallbackException may occurs on read char.

UnpackingStreamReader does not own source, so source still should be closed.

When the type of packed value is not known, use UnpackObject(Stream) instead.

/// is null. /// /// The of is false. /// /// is not valid MessagePack stream. /// Note that the state of will be unpredictable espicially it is not seekable. /// /// The unpacked result in the is not raw binary. /// Note that the state of will be unpredictable espicially it is not seekable. ///
public static UnpackCharStream ( Stream source ) : MsgPack.UnpackingStreamReader
source Stream The which contains Message Pack binary stream.
return MsgPack.UnpackingStreamReader
Beispiel #1
0
 public void TestUnpackCharStream_Stream_1ByteNonUtf8String_ExceptionInReaderOperation()
 {
     using (var stream = new MemoryStream(new byte[] { 0xA1, 0xFF }))
     {
         using (var result = Unpacking.UnpackCharStream(stream))
         {
             Assert.Throws <DecoderFallbackException>(() => result.Read());
         }
     }
 }
Beispiel #2
0
        public void TestUnpackCharStream_Stream_1Char_AsIsAndBounded()
        {
            using (var stream = new MemoryStream(new byte[] { 0xA1, ( byte )'A', 0xFF }))
            {
                using (var result = Unpacking.UnpackCharStream(stream))
                {
                    AssertStringReader(result, 1, "A");
                }

                // Assert is valid position on unerlying stream.
                Assert.That(Unpacking.UnpackInt32(stream), Is.EqualTo(-1));
            }
        }
Beispiel #3
0
        public void TestUnpackCharStream_Stream_Encoding_Empty_AsIsAndBounded()
        {
            using (var stream = new MemoryStream(new byte[] { 0xA0, 0xFF }))
            {
#if !NETFX_CORE && !SILVERLIGHT
                using (var result = Unpacking.UnpackCharStream(stream, Encoding.UTF32))
#else
                using (var result = Unpacking.UnpackCharStream(stream, Encoding.UTF8))
#endif // !NETFX_CORE && !SILVERLIGHT
                {
                    AssertStringReader(result, 0, String.Empty);
                }

                // Assert is valid position on unerlying stream.
                Assert.That(Unpacking.UnpackInt32(stream), Is.EqualTo(-1));
            }
        }
Beispiel #4
0
        public void TestUnpackCharStream_Stream_Encoding_1Byte_AsIsAndBounded()
        {
#if !NETFX_CORE && !SILVERLIGHT
            using (var stream = new MemoryStream(new byte[] { 0xA4, 0x00, 0x00, 0x00, ( byte )'A', 0xFF }))
#else
            using (var stream = new MemoryStream(new byte[] { 0xA2, 0x00, ( byte )'A', 0xFF }))
#endif // !NETFX_CORE && !SILVERLIGHT
            {
#if !NETFX_CORE && !SILVERLIGHT
                using (var result = Unpacking.UnpackCharStream(stream, new UTF32Encoding(bigEndian: true, byteOrderMark: false, throwOnInvalidCharacters: true)))
                {
                    AssertStringReader(result, 4, "A");
                }
#else
                using (var result = Unpacking.UnpackCharStream(stream, new UnicodeEncoding(bigEndian: true, byteOrderMark: false, throwOnInvalidBytes: true)))
                {
                    AssertStringReader(result, 2, "A");
                }
#endif // !NETFX_CORE && !SILVERLIGHT
                // Assert is valid position on unerlying stream.
                Assert.That(Unpacking.UnpackInt32(stream), Is.EqualTo(-1));
            }
        }
Beispiel #5
0
        public void TestUnpackCharStream_Stream_Encoding_1ByteNonSpecifiedString_ExceptionInReaderOperation()
        {
#if MONO
            Assert.Inconclusive("UTF32Encoding does not throw exception on Mono FCL.");
#endif
#if !NETFX_CORE
            using (var stream = new MemoryStream(new byte[] { 0xA4, 0x7F, 0x7F, 0x7F, 0x7F }))
            {
                using (var result = Unpacking.UnpackCharStream(stream, new UTF32Encoding(bigEndian: true, byteOrderMark: false, throwOnInvalidCharacters: true)))
                {
                    Assert.Throws <DecoderFallbackException>(() => result.Read());
                }
            }
#else
            using (var stream = new MemoryStream(new byte[] { 0xA5, 0xF8, 0x88, 0x80, 0x80, 0x80 }))
            {
                using (var result = Unpacking.UnpackCharStream(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true)))
                {
                    Assert.Throws <DecoderFallbackException>(() => result.Read());
                }
            }
#endif
        }
Beispiel #6
0
 public void TestUnpackCharStream_Stream_Encoding_EncodingIsNull()
 {
     Assert.Throws <ArgumentNullException>(() => Unpacking.UnpackCharStream(new MemoryStream(new byte[] { 0xA1, ( byte )'A' }), null));
 }
Beispiel #7
0
 public void TestUnpackCharStream_Stream_Encoding_StreamIsNull()
 {
     Assert.Throws <ArgumentNullException>(() => Unpacking.UnpackCharStream(null, Encoding.UTF8));
 }
Beispiel #8
0
 public void TestUnpackCharStream_Stream_Null()
 {
     Assert.Throws <ArgumentNullException>(() => Unpacking.UnpackCharStream(null));
 }